1.nginx配置增加状态
vim nginx_status.conf server { listen *:81 default_server; server_name _; location /nginx_status { stub_status on; access_log off; } location /upstream_status { check_status; access_log off; } location /req_status_server { req_status_show server; access_log off; } #location /req_status_url { # req_status_show url; # access_log off; #} }
2.测试访问
# curl http://localhost:81/nginx_status Active connections: 573 server accepts handled requests request_time 146168002 146168002 195194137 12912677608 Reading: 0 Writing: 13 Waiting: 560
3.创建监控脚本
vim nginx_stat.sh #!/bin/bash HOST="127.0.0.1" PORT="81" function ping { /sbin/pidof nginx | wc -l } function active { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}' } $1
4.增加配置文件参数
vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf UserParameter=nginx.status[*],/bin/bash /usr/local/zabbix-agent/scripts/nginx_stat.sh $1
5.重启进程
/etc/init.d/zabbix_agentd restart
6.增加模板
7.增加item
8.增加监控图像
9.查看监控