好久没有写博客了,今天遇到个麻烦事,网站的访问量忽然加大,监控报警是把个人机房带宽所有跑满了,最后把硬件防火墙的策略改动以后才恢复正常。而后负责人要关于nginx网站,和带宽的状态,因而就想起要作这个了,主要是监控nginx的一些连接状态:html
一、首先开启nginx_status模块监控功能:python
server { listen 8067; server_name localhost; root html; index index.html; access_log off; location /status { stub_status on; } }
二、测试:nginx
[root@WEB_007 vhosts]# curl http://192.168.10.7:8067/status Active connections: 3 server accepts handled requests 1305214152 1305214152 1305204005 Reading: 0 Writing: 3 Waiting: 0
三、编写脚本过滤数据:(zabbix主要有数据就能出图):bash
[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
四、开启zabbix脚本功能、我如今是习惯把执行的key,放在另外一个路径下,之后文件多了好区分,你们应该也建议这么作:curl
[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
五、导入模板:模块在个人附件能够本身下载:ide
这里演示,在那个时候我第一次制做,因此忘记添加图形了,你们能够本身根据模板添加图形,还有触发器我也没有建立,你们根据本身的须要进行建立
测试
六、图形查看效果:fetch