监控nginx
vi nginx.conf
server {
listen 801;
server_name localhost;
location /webstatus {
stub_status on;
access_log off;
#allow 127.0.0.1;
#allow 123.103.20.237;
#deny all;
}
}
在zabbix 加入配置
vi /usr/local/zabbix/etc/zabbix_agentd.conf
#nginx
UserParameter=nginx.accepts,/usr/local/sbin/nginx_status.sh accepts
UserParameter=nginx.handled,/usr/local/sbin/nginx_status.sh handled
UserParameter=nginx.requests,/usr/local/sbin/nginx_status.sh requests
UserParameter=nginx.connections.active,/usr/local/sbin/nginx_status.sh active
UserParameter=nginx.connections.reading,/usr/local/sbin/nginx_status.sh reading
UserParameter=nginx.connections.writing,/usr/local/sbin/nginx_status.sh writing
UserParameter=nginx.connections.waiting,/usr/local/sbin/nginx_status.sh waiting
vi /usr/local/sbin/nginx_status.sh
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: krish@toonheart.com
# License: GPLv2
# Set Variables
BKUP_DATE=`/bin/date +%Y%m%d`
LOG="/etc/zabbix/webstatus.log"
HOST=`/sbin/ifconfig eth1 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
PORT="801"
# Functions to return nginx stats
function active {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/webstatus" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
# Run the requested function
$1
chmod +x /usr/local/sbin/nginx_status.sh
重启agent服务:
/usr/local/zabbix/sbin/zabbix_agentd start
服务器端测试取值:
[root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 123.103.20.237 -p 10050 -k "nginx.accepts"
3
参考地址:
http://blog.sina.com.cn/s/blog_5611597901017qeh.html
在web控制台上传附件中的template