Nginx-解讀內置非默認模塊 ngx_http_stub_status_module

1.Backgroundnginx

  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 會看到這樣的信息:spa

Active connections: 291
server accepts handled requests
16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106

  其含義很容易理解:.net

  第一行
    當前的活躍鏈接數: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,沒有活動的鏈接。code


  Nginx 官方的解釋以下:server

    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

相關文章
相關標籤/搜索