zabbix-nginx监测及自定义模板
Posted 小怪獣55
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-nginx监测及自定义模板相关的知识,希望对你有一定的参考价值。
nginx安装[192.168.47.104]
#1.编译安装
wget https://nginx.org/download/nginx-1.14.2.tar.gz
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/apps/nginx --with-http_stub_status_module
make && make install
#2.修改配置
vim /apps/nginx/conf/nginx.conf
location /nginx_status
stub_status;
#3.启动
/apps/nginx/sbin/nginx
#4.访问
http://192.168.47.105/nginx_status
获取监控值
1.监控值脚本
host=$2:-127.0.0.1
port=$3:-80
page=$4:-nginx_status
info=$(/usr/bin/curl --connect-timeout 5 -s http://$host:$port/$page 2>/dev/null)
code=$(/usr/bin/curl --connect-timeout 5 -o /dev/null -s -w %http_code http://$host:$port/$page)
proc=$(/usr/bin/pgrep nginx | wc -l)
case "$1" in
status)
echo "$code $proc" | awk code=$1proc=$2ENDif(code == "200" && proc != 0)printf("%d\\n",1)elseprintf("%d\\n",0)
;;
active)
echo "$info" | awk /^Active/var=$NFENDif(var~/^[0-9]+$/)printf("%d\\n",var)elseprintf("%d\\n",0)
;;
reading)
echo "$info" | awk /Reading/ print $2
;;
writing)
echo "$info" | awk /Writing/ print $4
;;
waiting)
echo "$info" | awk /Waiting/ print $6
;;
accepts)
echo "$info" | awk NR==3 print $1
;;
handled)
echo "$info" | awk NR==3 print $2
;;
requests)
echo "$info" | awk NR==3 print $3
;;
restimes)
echo "$info" | awk BEGINOFMT="%.3f" NR==3 print $4/$3
;;
*)
echo "ZBX_NOTSUPPORTED"
;;
esac
2.修改zabbix_agentd.conf配置文件
mkdir /apps/zabbix_agent/conf.d/
以上脚本放在/apps/zabbix_agent/conf.d/目录中
vim /apps/zabbix_agent/etc/zabbix_agentd.conf
----------------------------------------------------------------------------------------------------
UserParameter=nginx.status[*],/apps/zabbix_agent/conf.d/check_nginx.sh $1chmod a+x check_nginx.sh
----------------------------------------------------------------------------------------------------
systemctl restart zabbix-agent
#在zabbic-server[192.168.47.102]机器上测试:
/usr/local/zabbix/bin/zabbix_get -s 192.168.47.104 -p 10050 -k "nginx.status[writing]"
web界面制作模板
以上是关于zabbix-nginx监测及自定义模板的主要内容,如果未能解决你的问题,请参考以下文章