今天网站的访问量突然加大,监控报警是把我的机房带宽全部跑满了,最后把硬件防火墙的策略改动之后才恢复正常。然后负责人要关于nginx网站,和带宽的状态,于是就想起要做这个了,主要是Zabbix监控nginx的一些链接状态:
1、首先开启nginx_status模块监控功能:
 server { 
        listen      8067; 
        server_name localhost;  
        root      html;  
        index  index.html; 
        access_log off; 
        location /status { 
          stub_status on; 
        } 
}
2、测试:
[root@WEB_007 vhosts]# curl :8067/status 
Active connections: 3 
server accepts handled requests 
 1305214152 1305214152 1305204005 
Reading: 0 Writing: 3 Waiting: 0
3、编写脚本过滤数据:(zabbix主要有数据就能出图):
[root@WEB_007 vhosts]# cat /usr/local/zabbix/scripts/nginx_status  
#!/bin/bash  
# Script to fetch nginx statuses for tribily monitoring systems  
# Author: xiaoluo 
# License: GPLv2  
  
function active {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Active' | awk '{print $NF}'  
}  
function reading {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Reading' | awk '{print $2}'  
}  
function writing {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Writing' | awk '{print $4}'  
}  
function waiting {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'  
}  
function accepts {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $1}'  
}  
function handled {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $2}'  
}  
function requests {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $3}'  
}  
# Run the requested function  
$1
4、开启zabbix脚本功能、我现在是习惯把执行的key,放在另一个路径下,以后文件多了好区分,大家应该也建议这么做:
[root@WEB_007 zabbix_agentd.conf.d]# vi /usr/local/zabbix/etc/zabbix_agentd.conf  
UnsafeUserParameters=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@WEB_007 zabbix_agentd.conf.d]#cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/ 
[root@WEB_007 zabbix_agentd.conf.d]#vi nginx 
#monitor nginx 
UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx_status $1
5、导入模板:模块在我的附件可以自己下载:
这里演示,在那个时候我第一次制作,所以忘记添加图形了,大家可以自己根据模板添加图形,还有触发器我也没有创建,大家根据自己的需要进行创建
6、图形查看效果:

总结:zabbix可以很好的根据应用来进行监控,还很强大,慢慢研究
模板在下面自己下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2015年资料/5月/14日/Zabbix 监控Nginx状态/
------------------------------------------分割线------------------------------------------
一些Zabbix相关教程集合:
CentOS 6.3下Zabbix安装部署

