环境:Centos 6.6
配置Nginx:
[root@localhost ~]# grep -v ‘#‘ /etc/nginx/conf.d/default.conf|grep -v ^$ server { listen 80; server_name 172.24.17.131; include /etc/nginx/default.d/*.conf; root /var/www/html; location / { index index.html index.htm; } location /status { stub_status on; access_log on; allow 172.24.17.131; deny all; } error_page 404 /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; } } [root@localhost ~]#
注:/status下的allow很重要,关系到后面zabbix_get是否能获取到值,如果获取不到会显示成Not Support
[root@localhost ~]# chmod a+x /usr/local/zabbix/bin/nginx_status.sh [root@localhost etc]# pwd /usr/local/zabbix/etc [root@localhost etc]# tail -2 zabbix_agentd.conf # Monitor Nginx UserParameter=Nginx.status[*],/bin/sh /usr/local/zabbix/scripts/Nginx_status.sh $1 [root@localhost etc]# [root@localhost ~]# grep UnsafeUserParameters /usr/local/zabbix/etc/zabbix_agentd.conf ### Option: UnsafeUserParameters UnsafeUserParameters=1 //开启自定义脚本功能,这个可以不开 [root@localhost ~]#
手动测试看能否获取到数据(zabbix_get):
[root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[active] 1 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[accepts] 163800 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[handled] 163801 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[requests] 163802 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[reading] 0 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[writing] 1 [root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Nginx.status[waiting] 0 [root@CentOS ~]#
下面在zabbix gui上新建模版(或导入模版):
Configuration--Templates--Create Template/Import
然后在Nginx status(Template)上的新建Items/Graphs
然后在主机上链接模版即可。
本文出自 “鹏城-酱油瓶” 博客,谢绝转载!
原文地址:http://yfshare.blog.51cto.com/8611708/1768060