zabbix监控之nginx
1,配置NginxStatus功能,需要ngx_http_stub_status_module模块支持
server {
listen 12345;
server_name 127.0.0.1;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
2,配置zabbix_agentd客户端
在zabbix_agentd.conf末尾添加如下配置
UserParameter=nginx.accepts,/data/scripts/nginx_status accepts
UserParameter=nginx.handled,/data/scripts/nginx_status handled
UserParameter=nginx.requests,/data/scripts/nginx_status requests
UserParameter=nginx.connections.active,/data/scripts/nginx_status active
UserParameter=nginx.connections.reading,/data/scripts/nginx_status reading
UserParameter=nginx.connections.writing,/data/scripts/nginx_status writing
UserParameter=nginx.connections.waiting,/data/scripts/nginx_status waiting
3,nginx状态监控脚本如下
cat nginx_status
#!/bin/bash # Script to fetch nginx_status statuses for tribily monitoring systems # Author: krish@toonheart.com # License: GPLv2 # Set Variables #HOST=`/sbin/ifconfig eth0 | sed -n ‘/inet /{s/.*addr://;s/ .*//;p}‘ HOST=127.0.0.1 PORT="12345" # Functions to return nginx_status stats function active { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| grep ‘Active‘ | awk ‘{print $NF}‘ } function reading { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| grep ‘Reading‘ | awk ‘{print $2}‘ } function writing { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘ } function waiting { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘ } function accepts { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| awk NR==3 | awk ‘{print $1}‘ } function handled { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| awk NR==3 | awk ‘{print $2}‘ } function requests { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2> /dev/null| awk NR==3 | awk ‘{print $3}‘ } # Run the requested function $1
4,重启nginx和zabbix_agentd
5,zabbix web界面添加nginx监控模板,添加nginx客户端监控项,nginx模板见附件
6,监控效果如下
本文出自 “jerrymin” 博客,请务必保留此出处http://jerrymin.blog.51cto.com/3002256/1675748
原文地址:http://jerrymin.blog.51cto.com/3002256/1675748