系统环境
- Zabbix Server:2.4.8
- ZABBIX服务端:192.168.5.254
- ZABBIX客户端:192.168.5.251
- 依赖软件包: net-tools
配置nginx.conf
1
| [root@master zabbix_agentd.d]
|
添加以下内容:
1 2 3 4 5 6 7
| location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.5.251; deny all; }
|
重启服务,测试是否可以正常访问nginx_status网页
添加nginx.conf
至/etc/zabbix/zabbix_agentd.d/
1
| [root@master zabbix_agentd.d]
|
1 2 3 4 5 6 7
| UserParameter=nginx.accepts,/etc/zabbix/zabbix_scripts/nginx_status.sh accepts UserParameter=nginx.handled,/etc/zabbix/zabbix_scripts/nginx_status.sh handled UserParameter=nginx.requests,/etc/zabbix/zabbix_scripts/nginx_status.sh requests UserParameter=nginx.connections.active,/etc/zabbix/zabbix_scripts/nginx_status.sh active UserParameter=nginx.connections.reading,/etc/zabbix/zabbix_scripts/nginx_status.sh reading UserParameter=nginx.connections.writing,/etc/zabbix/zabbix_scripts/nginx_status.sh writing UserParameter=nginx.connections.waiting,/etc/zabbix/zabbix_scripts/nginx_status.sh waiting
|
添加nginx_status.sh
至/etc/zabbix/zabbix_scripts/
内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #!/bin/bash
HOST=`/sbin/ifconfig eno16777736 | grep "inet " | awk '{print $2}'` PORT="80" URI="nginx_status"
function active { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://$HOST:$PORT/$URI" 2> /dev/null| awk NR==3 | awk '{print $3}' }
$1
|
转载请注明出处:使用zabbix监控Nginx原文地址:https://www.xiaotanzhu.com/%E8%BF%90%E7%BB%B4/2016-07-30-monitor-nginx-with-zabbix.html