码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix监控nginx

时间:2015-01-19 10:48:08      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

首先在agent端的nginx.conf中添加下面内容

# vim /usr/local/nginx/conf/nginx.conf

server {
           listen 80;
           server_name localhost;

           location /nginxstatus{
                                          stub_status on;
                                          access_log off;
                                          allow 127.0.0.1;
                                          allow 192.168.1.0/24;                ----->zabbix server端的IP地址
                                          deny all;
                                          }

}

 

然后写监控nginx状态的脚本

# vim /usr/local/zabbix/scripts/nginx.status.sh

#!/bin/bash
function active {
                       curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk ‘/Active/ {print $3}‘
}
function reading {
                         curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk ‘/Reading/ {print $2}‘
}
function writing {
                        curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk ‘/Writing/ {print $4}‘
}
function waiting {
                       curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk ‘/Waiting/ {print $6}‘
}
function accepts {
                         curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk NR==3|awk ‘{print $1}‘
}
function handled {
                         curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk NR==3|awk ‘{print $2}‘

}

function requests {
                         curl "http://127.0.0.1/nginxstatus" 2>/dev/null|awk NR==3|awk ‘{print $3}‘

}

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

修改权限

# chmod 755 /usr/local/zabbix/scripts/mysql.status.sh

测试脚本

# /usr/local/zabbix/scripts/nginx.status.sh active
1

 

修改zabbix agent的配置文件

# vim /usr/local/zabbix/etc/zabbix_agentd.conf

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/      --->配置文件key的路径

UnsafeUserParameters=1                                            ---》允许特殊字符

 

增加nginx key的配置文件

# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.status.conf

UserParameter=nginx.accepts,/usr/local/zabbix/scripts/nginx.status.sh accepts
UserParameter=nginx.handled,/usr/local/zabbix/scripts/nginx.status.sh handled
UserParameter=nginx.requests,/usr/local/zabbix/scripts/nginx.status.sh requests
UserParameter=nginx.active,/usr/local/zabbix/scripts/nginx.status.sh active
UserParameter=nginx.reading,/usr/local/zabbix/scripts/nginx.status.sh reading
UserParameter=nginx.writing,/usr/local/zabbix/scripts/nginx.status.sh writing
UserParameter=nginx.waiting,/usr/local/zabbix/scripts/nginx.status.sh waiting

然后agent端测试

# /usr/local/zabbix/sbin/zabbix_agentd -t nginx.active
nginx.active [t|1]

重启agent服务

service zabbix_agentd restart

在zabbix添加nginx模板key查看即可

 

zabbix监控nginx

标签:

原文地址:http://www.cnblogs.com/liqing1009/p/4233021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!