您好,欢迎访问一九零五行业门户网

zabbix 监控 nginx_status

1. 配置nginx stuats # vi /etc/nginx/nginx.conf and add the following to your server block location ~ ^/nginxstatus/ { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.0.3; // put your servers ipaddress instead of 192.168.0.3
1. 配置nginx stuats
# vi /etc/nginx/nginx.conf
and add the following to your server block
location ~ ^/nginxstatus/ {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
        allow 192.168.0.3;    // put your servers ipaddress instead of 192.168.0.3
        deny all;
        }
reload nginx
# nginx -s reload
2. zabbix客户端配置
/etc/zabbix/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
3.脚本内容:
[root@localhost bin]# cat nginx_status.sh
#!/bin/bash
# script to fetch nginx statuses for tribily monitoring systems
# author: user@domainname
# license: gplv2
# set variables
bkup_date=`date +%y%m%d`
log=/var/log/zabbix/webstatus.log
host=`ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
port=80
# 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
其它类似信息

推荐信息