Zabbix监控nginx
编辑nginx.conf文件
//在server内部添加一下内容 location /nginx-status { stub_status on; access_log off; allow 127.0.0.1; //192.168.1.101宿主机ip allow 192.168.1.101; deny all; }
平滑重启nginx
//nginx的pid文件储存位置/usr/local/nginx/logs/nginx.pid kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
2.zabbix agentd客户端配置
//编辑/usr/local/zabbix/etc/zabbix_agentd.conf //在文件末尾添加如下 UnsafeUserParameters=1 UserParameter=nginx.accepts,/usr/local/zabbix/scripts/nginx_status.sh accepts UserParameter=nginx.handled,/usr/local/zabbix/scripts/nginx_status.sh handled UserParameter=nginx.requests,/usr/local/zabbix/scripts/nginx_status.sh requests UserParameter=nginx.connections.active,/usr/local/zabbix/scripts/nginx_status.sh active UserParameter=nginx.connections.reading,/usr/local/zabbix/scripts/nginx_status.sh reading UserParameter=nginx.connections.writing,/usr/local/zabbix/scripts/nginx_status.sh writing UserParameter=nginx.connections.waiting,/usr/local/zabbix/scripts/nginx_status.sh waiting
3.编辑nginx_status.sh文件
cat /usr/local/zabbix/scripts/nginx_status.sh #!/bin/bash HOST=127.0.0.1 PORT="80" TERM=$1 # Functions to return nginx stats 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}‘ } $TERM
4.重启zabbix_agentd
service zabbix_agentd restart
5.zabbixweb控制端导入模板
6.zabbix监控的客户端添加nginx模块
本文出自 “ubuntu” 博客,请务必保留此出处http://thankinglove.blog.51cto.com/2311485/1793288
原文地址:http://thankinglove.blog.51cto.com/2311485/1793288