zabbix 针对nginx 状态监控
环境:Centos 6.5zabbix 2.0
Zabbix Server: 192.168.137.132
Zabbix nginx 客户端: 192.168.137.130
前提是nignx在编译安装时加上:--with-http_stub_status_module-----这个大家都知道!!
同时还要在nginx的配置文件中加上:
location /status
{
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.137.132; #这是我们zabbix监控服务器IP
}
下面说下zabbix对nginx的监控原理:
Zabbix Server nginx客户端key(要写入客户端配置文件中) nginx状态参数
nginx web界面nginx状态显示情况如下图:
Zabbix监控nginx_status
1.创建获取nginx的status参数数据传送到server端脚本
#cat >> /usr/local/sbin/nginx_status.sh /dev/null| grep'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| grep'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awkNR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awkNR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/status" 2>/dev/null| awkNR==3 | awk '{print $3}'
}
#Run the requested function
$1
EOF
这个脚本当中定义了一些状态项名称的函数,函数的功能是通过curl这个工具抓取到nginxweb页面的状态数据。
2.添加agent客户端key值,以便让zabbix server获取状态数据
cat>>/etc/zabbix/zabbix_agentd.conf
页:
[1]