很久没有写博客了,今天遇到个麻烦事,网站的访问量突然加大,监控报警是把我的机房带宽全部跑满了,最后把硬件防火墙的策略改动之后才恢复正常。然后负责人要关于nginx网站,和带宽的状态,于是就想起要做这个了,主要是监控nginx的一些链接状态:
1、首先开启nginx_status模块监控功能:
|
1
2
3
4
5
6
7
8
9
10
|
server { listen 8067;
server_name localhost;
root html;
index index.html;
access_log off;
location /status {
stub_status on;
}
} |
2、测试:
|
1
2
3
4
5
|
[[email protected]_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
|
3、编写脚本过滤数据:(zabbix主要有数据就能出图):
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[[email protected]_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,放在另一个路径下,以后文件多了好区分,大家应该也建议这么做:
|
1
2
3
4
5
6
7
|
[[email protected]_007 zabbix_agentd.conf.d]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
UnsafeUserParameters=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
[[email protected]_007 zabbix_agentd.conf.d]#cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[[email protected]_007 zabbix_agentd.conf.d]#vi nginx
#monitor nginxUserParameter=nginx[*],/usr/local/zabbix/scripts/nginx_status $1
|
5、导入模板:模块在我的附件可以自己下载:
这里演示,在那个时候我第一次制作,所以忘记添加图形了,大家可以自己根据模板添加图形,还有触发器我也没有创建,大家根据自己的需要进行创建
6、图形查看效果:
本文转自 小罗ge11 51CTO博客,原文链接:http://blog.51cto.com/xiaoluoge/1642194,如需转载请自行联系原作者