1.1 系統環境nginx
centos6.6 zabbix2.28 nginx1.4+
1.2 配置nginx支持狀態 centos
#根據本身的環境配置
bash
server { location /nginxstatus { stub_status on; access_log off; allow 172.16.10.0/24 ; deny all; }
#測試查看狀態,出現結果,配置沒問題
服務器
curl http://10.10.10.101/nginxstatus Active connections: 1 server accepts handled requests 1653507 1653507 1686937 Reading: 0 Writing: 1 Waiting: 0
1.3 配置zabbix客戶端curl
[root@bds01 ~]# cat /etc/zabbix/zabbix_agentd.d/nginx.conf UserParameter=nginx.status[*],/data/sh/zabbix_sh/zabbix_nginx.sh $1
1.4 腳本配置文件ide
[root@bds01 ~]# cat /data/sh/zabbix_sh/zabbix_nginx.sh #!/bin/bash HOST=`ifconfig| grep -EA 2 "(eth1|em2)"| awk '/inet/{print $2}'| cut -d: -f 2|head -1 ` PORT=80# echo $HOST #echo $PORT function ping { /sbin/pidof nginx | wc -l } # 檢測nginx性能 function active { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| grep 'Active' | awk '{print $NF}'} function reading { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| grep 'Reading' | awk '{print $2}'} function writing { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| grep 'Writing' | awk '{print $4}'} function waiting { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'} function accepts { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| awk NR==3 | awk '{print $1}'} function handled { /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| awk NR==3 | awk '{print $2}'} function requests{ /usr/bin/curl "http://$HOST:$PORT/nginxstatus/" 2>/dev/null| awk NR==3 | awk '{print $3}'} # 執行function $1
1.5 重啓zabbix客戶端性能
[root@bds01 ~]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [肯定] Starting Zabbix agent: [肯定]
1.6 zabbix服務器端測試測試
zabbix_get -s 10.10.10.101 -k 'nginx.status[active]' 1
1.7 導入模板,綁定模板url