64532 发表于 2016-4-27 08:47:24

Zabbix监控Nginx

环境:Centos 6.6

配置Nginx:

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
# grep -v '#' /etc/nginx/conf.d/default.conf|grep -v ^$
server {
    listen       80;
    server_name172.24.17.131;
    include /etc/nginx/default.d/*.conf;
    root /var/www/html;
    location / {
      indexindex.html index.htm;
    }
    location /status {
stub_status on;
access_log on;
allow 172.24.17.131;
deny all;
    }
    error_page404            /404.html;
    location = /404.html {
      root   /usr/share/nginx/html;
    }
    error_page   500 502 503 504/50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
}
#





注:/status下的allow很重要,关系到后面zabbix_get是否能获取到值,如果获取不到会显示成Not Support


1
2
3
4
5
6
7
8
9
10
11
# chmod a+x /usr/local/zabbix/bin/nginx_status.sh
# pwd
/usr/local/zabbix/etc
# tail -2 zabbix_agentd.conf
# Monitor Nginx
UserParameter=Nginx.status,/bin/sh /usr/local/zabbix/scripts/Nginx_status.sh $1
#
# grep UnsafeUserParameters /usr/local/zabbix/etc/zabbix_agentd.conf
### Option: UnsafeUserParameters
UnsafeUserParameters=1               //开启自定义脚本功能,这个可以不开
#





手动测试看能否获取到数据(zabbix_get):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# zabbix_get -s 172.24.17.131 -k Nginx.status
1
# zabbix_get -s 172.24.17.131 -k Nginx.status
163800
# zabbix_get -s 172.24.17.131 -k Nginx.status
163801
# zabbix_get -s 172.24.17.131 -k Nginx.status
163802
# zabbix_get -s 172.24.17.131 -k Nginx.status
0
# zabbix_get -s 172.24.17.131 -k Nginx.status
1
# zabbix_get -s 172.24.17.131 -k Nginx.status
0
#





下面在zabbix gui上新建模版(或导入模版):
Configuration--Templates--Create Template/Import


然后在Nginx status(Template)上的新建Items/Graphs



然后在主机上链接模版即可。
最后的效果图:




页: [1]
查看完整版本: Zabbix监控Nginx