Zabbix监控Nginx状态

Zabbix监控Nginx状态,首先,在nginx的配置文件中添加如下一段代码

server

 listen localhost:80; 
 server_name localhost;
location /nginxstatus { 
 stub_status on; 
 access_log off; 
 allow 127.0.0.1;
 allow 192.168.1.165; 
 deny all; 
 } 
}
保存之后重启nginx

在zabbix脚本目录下创建脚本监控zabbix状态
#!/bin/bash 
# Script to fetch nginx statuses for tribily monitoring systems 
# Author: admin@linuxidc.com 
# License: GPLv2


# Set Variables 


# Functions to return nginx stats
nginx=/usr/local/zabbix-2.4.4/scripts/nginx.txt
function active {
                curl "http://localhost/nginxstatus"&>$nginx && awk '/Active/{print $3}' $nginx
}


function reading {
                curl "http://localhost/nginxstatus"&>$nginx && awk '/Reading/{print $2}' $nginx
}


function writing {
                curl "http://localhost/nginxstatus"&>$nginx && awk '/Writing/{print $4}' $nginx
}


function waiting {
                curl "http://localhost/nginxstatus"&>$nginx && awk '/Waiting/{print $6}' $nginx
}


function accepts {
                curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk '{print $1}'
}


function handled {
                curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk '{print $2}'
}


function requests {
                curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk '{print $3}'
}


# Run the requested function 
case "$1" in
active)
        active
        ;;
reading)
        reading
        ;;
writing)
        writing
        ;;
waiting)
        waiting
        ;;
accepts)
        accepts
        ;;
handled)
        handled
        ;;
requests)
        requests
        ;;
*)
        echo "Usage: $0 {nginx_site_dicovery}"
                echo "Usage: $0 {active [host] | reading [host] | writing [host] | waiting [host] | accepts [host] | handled [host] | requests [host]}"
esac

然后修改该文件的属主和属组为zabbix,并且具有执行权限
chown zabbix.zabbix /usr/local/zabbix-2.4.4/scripts/nginx_status
chmod 755 /usr/local/zabbix-2.4.4/scripts/nginx_status
再创建一个nginx.txt的文件,将属组和属主定为zabbix,具有读写权限
然后在zabbix_agentd.conf配置文件中添加如下代码
#monitor nginx 
UserParameter=nginx.accepts,/usr/local/zabbix-2.4.4/scripts/nginx_status accepts 
UserParameter=nginx.handled,/usr/local/zabbix-2.4.4/scripts/nginx_status handled 
UserParameter=nginx.requests,/usr/local/zabbix-2.4.4/scripts/nginx_status requests 
UserParameter=nginx.connections.active,/usr/local/zabbix-2.4.4/scripts/nginx_status active 
UserParameter=nginx.connections.reading,/usr/local/zabbix-2.4.4/scripts/nginx_status reading 
UserParameter=nginx.connections.writing,/usr/local/zabbix-2.4.4/scripts/nginx_status writing 
UserParameter=nginx.connections.waiting,/usr/local/zabbix-2.4.4/scripts/nginx_status waiting
这段代码可以视自己目录情况而改变


创建好了之后就可以在web页面配置item监控项了

一些Zabbix相关教程集合

安装部署分布式监控系统Zabbix 2.06

《安装部署分布式监控系统Zabbix 2.06》

CentOS 6.3下Zabbix安装部署

Zabbix分布式监控系统实践

CentOS 6.3下Zabbix监控apache server-status

CentOS 6.3下Zabbix监控MySQL数据库参数

64位CentOS 6.2下安装Zabbix 2.0.6   

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/f197249c6405446934089480a1a026cf.html