###该内容主要是为留个备忘,感谢我的同事Bob在前面给我排雷!!
1:
在需要监控的网站的相应配置文件里()加入以下部分:
location /nginx-status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow xxx.xxx.xxx.xxx;#本机IP
allow xxx.xxx.xxx.xxx; #监控服务器的Ip
deny all;
}
2:
将userparameter_nginx.conf 放到/usr/local/zabbix/etc/zabbix_agent.conf.d目录下,该文件的内容如下;
-
UserParameter=nginx.accepts,/usr/local/zabbix/sbin/nginx-status.sh accepts
-
UserParameter=nginx.handled,/usr/local/zabbix/sbin/nginx-status.sh handled
-
UserParameter=nginx.requests,/usr/local/zabbix/sbin/nginx-status.sh requests
-
UserParameter=nginx.connections.active,/usr/local/zabbix/sbin/nginx-status.sh active
-
UserParameter=nginx.connections.reading,/usr/local/zabbix/sbin/nginx-status.sh reading
-
UserParameter=nginx.connections.writing,/usr/local/zabbix/sbin/nginx-status.sh writing
-
UserParameter=nginx.connections.waiting,/usr/local/zabbix/sbin/nginx-status.sh waiting
并在/usr/local/zabbix/etc/zabbix_agentd.conf中 include该文件;
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_nginx.conf
3:显然这里需要用到nginx_status.sh文件,该文件的位置在/usr/local/zabbix/sbin/下,该文件内容如下:
-
#!/bin/bash# Script to fetch nginx statuses for tribily monitoring systems
-
# Author: [email]krish@toonheart.com[/email]
-
# License: GPLv2
-
-
HOST=lo***b.g***z.com ##要监控的域名
-
HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'` ##和机器上的相对应
-
PORT="8080"
-
#webstatus=nginx-status
-
-
# Functions to return nginx stats
-
-
function active {
-
/usr/bin/curl "" 2>/dev/null| grep 'Active' | awk '{print $NF}'
-
}
-
-
function reading {
-
/usr/bin/curl "" 2>/dev/null| grep 'Reading' | awk '{print $2}'
-
}
-
-
function writing {
-
/usr/bin/curl "" 2>/dev/null| grep 'Writing' | awk '{print $4}'
-
}
-
-
function waiting {
-
/usr/in/curl "" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
-
}
-
-
function accepts {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $1}'
-
}
-
-
function handled {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $2}'
-
}
-
-
function requests {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $3}'
-
}
-
-
# Run the requested function
-
$1
4:测试:
/usr/local/zabbix/bin/zabbix_get -s 客户端IP -p 10050 -k "nginx.connections.active"
7
5:在监控服务器上添加主机,并导入nginx模板,nginx模板!
然后即可显示相关内容,如果没有数据,查看日志文件,根据日志文件解决问题即可!
阅读(2442) | 评论(0) | 转发(0) |