X

啟用 Nginx Status 的設定

要看 Apache Loading 的狀況, 可以看 Apache Status, 但是 Nginx server 的 loading / Status 要怎麼查看呢?

啟用 Nginx Status 的設定步驟

設定參考: Nginx Http Stub Status

  1. vim /etc/nginx/sites-available/default
    server {
    ...
        location /nginx_status {
            stub_status on;
            access_log off;
            allow 123.123.123.123; # 允許看到的 IP
            allow 127.0.0.1;
            deny all;
        }
    }
  2. /etc/init.d/nginx restart
  3. curl http://localhost/nginx_status # 查看 Nginx status

curl nginx_status 的回傳格式如下:

Active connections: 816
server accepts handled requests
 39600484 39600484 24795538
Reading: 0 Writing: 4 Waiting: 794

下述說明摘錄自此篇:Module ngx_http_stub_status_module

  • Active connections
    • The current number of active client connections including Waiting connections.
  • accepts
    • The total number of accepted client connections.
  • handled
    • The total number of handled connections. Generally, the parameter value is the same as accepts unless some resource limits have been reached (for example, the worker_connections limit).
  • requests
    • The total number of client requests.
  • Reading
    • The current number of connections where nginx is reading the request header.
  • Writing
    • The current number of connections where nginx is writing the response back to the client.
  • Waiting
    • The current number of idle client connections waiting for a request.

監看 Nginx status 的 Script

監控 Status 的 Script, 讓 Status 比較容易看

  1. wget https://raw.githubusercontent.com/magicdrums/Scripts/master/nginxstats.py
  2. chmod +x ./nginxstats.py
  3. ./nginxstats.py http://localhost/nginx_status
  4. 其它參數:nginxstats.py --servers="http://localhost/nginx_status" --time=5

相關網頁

Tsung: 對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
Related Post