zabbix-----監控nginx連接數
阿新 • • 發佈:2019-04-16
tin writing 執行 sts col 效果 $2 監控項 .com
1、修改nginx配置文件,在nginx.conf中添加如下內容
1 location /status { 2 stub_status on; 3 access_log off; 4 }
2、加載配置文件,nginx -s reload
3、測試是否生效,執行如下命令:
1 curl -s http://127.0.0.1:80/status 2 3 執行結果: 4 Active connections: 24071 5 server accepts handled requests 6 17846876 17846876 177647487 Reading: 0 Writing: 19601 Waiting: 2937
4、通過awk提取需要Active、accepts、handled、requests,測試是否提取成功
1 curl -s http://127.0.0.1:80/status|grep Active|awk -F "[ ]" ‘{print $3}‘ 2 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $1‘} 3 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $2‘}4 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $3‘}
5、zabbix_agent.conf 加入UserParameter,編輯配置文件,找到UserParameter,增加如下內容
1 UserParameter= nginx.active,/usr/bin/curl -s http://127.0.0.1:80/status|grep Active|awk -F "[ ]" ‘{print $3}‘ 2 UserParameter= nginx.accepts,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $1‘}3 UserParameter= nginx.handled,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $2‘} 4 UserParameter= nginx.requests,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {‘print $3‘}
6、重啟zabbix_agent服務,進入到web監控頁面配置
7、配置--->主機--->監控項--->創建監控項,如下圖:
8、配置--->主機--->圖形--->創建圖形,如下圖:
9、最終效果如下圖:
zabbix-----監控nginx連接數