zabbix 通过status模块监控nginx

1、编辑nginx的配置文件,在server下添加如下内容:

location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

保存退出并重启nginx

2、创建监控nginx的脚本目录

mkdir /usr/local/zabbix/libexec

3、vim /usr/local/zabbix/libexec/nginx.sh && chmod +x /usr/local/zabbix/libexec/nginx.sh

#!/bin/bash
##################################################
# Description:zabbix 通过 status 模块监控 nginx
# Note:Zabbix 3.2
# DateTime: 2016-11-22
##################################################

HOST="localhost"
PORT="80"

function ping {
/sbin/pidof nginx | wc -l
}

function active() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function accepts() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
function reading() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting() {
/usr/bin/curl -s "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}


case "$1" in
active)
active
;;
accepts)
accepts
;;
handled)
handled
;;
requests)
requests
;;
reading)
reading
;;
writing)
writing
;;
waiting)
waiting
;;

*)
echo $"Usage $0 {active|accepts|handled|requests|reading|writing|waiting}"
exit
esac

4、创建zabbix_agentd 监控的key

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_nginx.conf

UserParameter=nginx.status[*],/usr/local/zabbix/libexec/nginx.sh $1

重启zabbix_agentd

5、测试脚本及key

[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_nginx.conf
[root@zabbix ~]# /usr/local/zabbix/libexec/nginx.sh -h
Usage /usr/local/zabbix/libexec/nginx.sh {active|accepts|handled|requests|reading|writing|waiting}
[root@zabbix ~]# /usr/local/zabbix/libexec/nginx.sh accepts
2016

[root@zabbix ~]# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -k 'nginx.status[accepts]'
965

6、导入模板以及管理主机

模板:nginx.xml

zabbix 通过status模块监控nginx

7、验证

zabbix 通过status模块监控nginx

 

 


      本文转自Mr_chen  51CTO博客,原文链接:http://blog.51cto.com/metis/1945267,如需转载请自行联系原作者





上一篇:直播间搭建,主播和功能的结合才能发挥直播最大效力


下一篇:短视频商城源码,两种方式实现点击出现弹窗显示