標籤:執行個體 服務 access 長串連 介紹 server reads sed head
1.Background
ngx_http_stub_status_module 是一個 Nginx 的內建 HTTP 模組,該模組可以提供 Nginx 的狀態資訊。預設情況下這個模組是不被編譯進來的,所以在編譯 Nginx 時要指定載入該模組:
--with-http_stub_status_module
當然了,如果你是重新編譯,僅僅-s reload是不夠的,可能需要用到平滑升級:《高效能Web伺服器Nginx的配置與部署研究(14)平滑升級你的Nginx》。
為什麼拿它做例子?因為它也是個足夠短小精悍的模組,是一個典型 handler 模組。那麼以後我們講解模組的過程,都是:
1).簡要的介紹
2).使用的執行個體
3).指令介紹
4).源碼分析
2.Simple example
location /nginx_status { #copied from http://blog.kovyrin.net/2006/04/29/monitoring-nginx-with-rrdtool/ stub_status on; access_log off; allow SOME.IP.ADD.RESS; deny all;}
我們假設你是在本機上實驗,並且開啟的是 80 連接埠,那麼在瀏覽器中輸入:http://localhost/nginx_status 會看到這樣的資訊:
Active connections: 291server accepts handled requests16630948 16630948 31070465Reading: 6 Writing: 179 Waiting: 106
其含義很容易理解:
第一行
當前的活躍串連數:291 #個人認為是處於 SYN_RCVD、ESTABLISHED 狀態的串連,等於 Reading + Writing + Waiting
第二行
伺服器已接受的串連數:16630948(accepted connection #),已接收來自用戶端的串連數,也是被Worker進程接收的串連數。
伺服器已處理的串連數:16630948(handled connection #),已被處理的串連總數,其值一般與accepts相等,除非受到了某些資源的限制,如:設定了worker_connections的數量限制。
伺服器已處理的請求:31070465(可以算出,平均每個串連有 1.8 個請求)(handled connection #)
第三行
Reading – Nginx 正在讀取要求標頭的串連數為 6;
Writting – Nginx 正在讀取請求體、處理請求並發送響應給用戶端的串連數為 179;
Waiting – 當前活動的長串連數:106。 #只是keep-alive,沒有活動的串連。
Nginx 官方的解釋如下:
active connections – number of all open connections
server accepts handled requests – nginx accepted 16630948 connections, handled 16630948 connections (no one was closed just it was accepted), and handles 31070465 requests (1.8 requests per connection)
reading – nginx reads request header
writing – nginx reads request body, processes request, or writes response to a client
waiting – keep-alive connections, actually it is active - (reading + writing)
3 Directives
這個模組中的唯一一個指令,是:
stub_status
文法:stub_status on
範圍:location
功能:統計這個 location 的資訊。
轉自:http://blog.csdn.net/poechant/article/details/7627843
Nginx-解讀內建非預設模組 ngx_http_stub_status_module