1、首先打开nginx的状态页
location /nginx_status {stub_status on;}
2、进行访问测试
curl http://127.0.0.1/nginx_status
Active connections: 1
server accepts handled requests1 1 1
Reading: 0 Writing: 1 Waiting: 0
3、在客户端编写脚本进行数据采集
编写脚本方便采集不用一个个配置
脚本如下
#!/bin/bash
############################################################
# $Name: nginx_status.sh
# $Version: v1.0
# $Function: Nginx Status
# $Author: DriverZeng
# $organization: blog.driverzeng.com
# $Create Date: 2016-06-23
# $Description: Monitor Nginx Service Status
############################################################NGINX_PORT=80 #如果端口不同仅需要修改脚本即可,否则修改xml很麻烦
NGINX_COMMAND=$1nginx_active(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
}nginx_reading(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
}nginx_writing(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'}nginx_waiting(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'}nginx_accepts(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'}nginx_handled(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'}nginx_requests(){/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'}case $NGINX_COMMAND inactive)nginx_active;;;reading)nginx_reading;;;writing)nginx_writing;;;waiting)nginx_waiting;;;accepts)nginx_accepts;;;handled)nginx_handled;;;requests)nginx_requests;;;*)echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"esac
4、给脚本添加执行权限
chmod +x /etc/zabbix/scripts/nginx_status.sh
5、配置监控项
#客户端
cat /etc/zabbix/zabbix_agentd.d/nginx_status.conf
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/scripts/nginx_status.sh "$1"
6、重启
systemctl restart zabbix-agent
7、服务端测试
zabbix_get -s 客户端ip -k nginx_status[writing]
1
8、添加监控项