首先nginx要配置启用status
一、在客户端放置监控脚本:
cat /etc/zabbix/monitor_scripts/nginx_status.sh //路径名称可自己选,配置UserParameter时指定这个脚本
#!/bin/bash HOST=127.0.0.1 PORT="80" # 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}‘ } # Run the requested function $1
二、配置zabbix客户端:
配置zabbix_agentd.conf,使UnsafeUserParameters=1 //这个似乎不是必要的,我试过0或者注释都可以
然后添加监控配置,有两种方式:
1.修改zabbix_agentd.conf文件
2.开启包含文件Include=
添加如下配置
UserParameter=nginx.accepts,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh accepts UserParameter=nginx.handled,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh handled UserParameter=nginx.requests,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh requests UserParameter=nginx.connections.active,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh active UserParameter=nginx.connections.reading,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh reading UserParameter=nginx.connections.writing,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh writing UserParameter=nginx.connections.waiting,/bin/bash /etc/zabbix/monitor_scripts/nginx_status.sh waiting
三:在zabbix web导入配置模板(附件,网上找滴)
注意:确保zabbix_agentd.conf里hostname配置正确,网上很多文章没有提这点,刚开始我也没注意,导致配置完监控不了,没有采集到数据
原文地址:http://ice914.blog.51cto.com/1002165/1679058