歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 開啟nginx狀態監控

開啟nginx狀態監控

日期:2017/3/1 16:32:15   编辑:關於Linux
開啟nginx狀態監控 1.nginx的ngx_http_stub_status_module提供能夠獲取Nginx自上次啟動以來的工作狀態 的功能。 www.2cto.com 如果是編譯安裝的話,需要–with-http_stub_status_module激活 2.該模塊是基於某個server的,所以必須在server裡面 3.nginx.conf配置 01 server 02 { 03 listen 80; 04 server_name blog.xfz.com; 05 index index.html index.htm index.php; 06 root /data0/htdocs/blog; 07 08 #limit_conn crawler 20; 09 10 location ~ .*\.(php|php5)?$ 11 { 12 #fastcgi_pass unix:/tmp/php-cgi.sock; 13 fastcgi_pass 127.0.0.1:9000; 14 fastcgi_index index.php; 15 include fcgi.conf; 16 } 17 18 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 19 { 20 expires 30d; 21 } 22 23 location ~ .*\.(js|css)?$ 24 { 25 expires 1h; 26 } 27 location /nginx_status { 28 stub_status on; 29 access_log off; 30 allow 192.168.1.1;#設置為可訪問該狀態信息的ip 31 deny all; 32 } 33 log_format access '$remote_addr - $remote_user [$time_local] "$request" ' 34 '$status $body_bytes_sent "$http_referer" ' 35 '"$http_user_agent" $http_x_forwarded_for'; 36 access_log /data1/logs/access.log access; 37 } 38 其中狀態的配置 1 location /nginx_status { 2 stub_status on; 3 access_log off; 4 allow 192.168.1.1;#設置為可訪問該狀態信息的ip 5 deny all; 6 } 1 然後,reload一下nginx的配置 2 通過http://blog.xfz.com<span></span>/nginx_status 即可訪問 狀態值: Active connections: 1 server accepts handled requests 14 14 21 Reading: 0 Writing: 1 Waiting: 0 解釋: active connections:nginx 正處理的活動連接數 20個。 server accepts handled requests:nginx啟動到現在共處理了 200個連接 , 成功創建 200 次握手 一般跟第一個一樣,差值為請求丟失數, 總共處理了286 次請求。 reading :nginx 讀取到客戶端的 Header 信息數。 writing : nginx 返回給客戶端的 Header 信息數。 waiting :開啟 keep-alive 的情況下,這個值等於 active - (reading + writing),意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留連接。 這個狀態信息,從nginx啟動算起,包括重載配置文件,也會清零 也可以通過命令查看 01 #netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’ 02 03 04 TIME_WAIT 17 05 ESTABLISHED 3254 06 LAST_ACK 236 07 FIN_WAIT_1 648 08 FIN_WAIT_2 581 09 CLOSING 7 10 CLOSE_WAIT 4916 11 12 解析: 13 CLOSED //無連接是活動的或正在進行 14 LISTEN //服務器在等待進入呼叫 15 SYN_RECV //一個連接請求已經到達,等待確認 16 SYN_SENT //應用已經開始,打開一個連接 17 ESTABLISHED //正常數據傳輸狀態/當前並發連接數 18 FIN_WAIT1 //應用說它已經完成 19 FIN_WAIT2 //另一邊已同意釋放 20 ITMED_WAIT //等待所有分組死掉 21 CLOSING //兩邊同時嘗試關閉 22 TIME_WAIT //另一邊已初始化一個釋放 23 LAST_ACK //等待所有分組死掉
Copyright © Linux教程網 All Rights Reserved