亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述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监测及自定义模板】
推荐阅读
- Ubuntu下开启/关闭防火墙及端口#私藏项目实操分享#
- #yyds干货盘点#Linux用户和组
- #yyds干货盘点#Centos7更换阿里YUM源
- 推荐几款大家常使用的 SSH 客户端工具
- ubuntu18.04升级kennel 5.10失败记录 #yyds干货盘点#
- #yyds干货盘点#Linux简介
- dgango中admin下添加搜索功能
- #yyds干货盘点#Linux进程
- 蓝魔平板电脑将推出采纳Windows 8.1设置系统的i10s【图】