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、添加監控項