zabbix7.2最新版本 nginx自定义监控(三) 设置触发器
安装zabbix-get服务
在zabbix-server端口安装zabbix-get服务
[root@localhost ~]# dnf install -y zabbix-get
Last metadata expiration check: 1:55:49 ago on Wed 14 May 2025 09:24:49 AM CST.
Dependencies resolved.
==================================================================================================================================================================Package Architecture Version Repository Size
==================================================================================================================================================================
Installing:zabbix-get x86_64 7.2.6-release1.el9 zabbix 431 k
监控Nginx
安装启动nginx
[root@localhost zabbix_agentd.d]# dnf install -y nginx
Last metadata expiration check: 3:50:02 ago on Wed 14 May 2025 09:50:53 AM CST.
Dependencies resolved.[root@localhost zabbix_agentd.d]# systemctl restart nginx
[root@localhost zabbix_agentd.d]# netstat -pltun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 41194/zabbix_agentd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1420/sshd: /usr/sbi
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 45869/nginx: master
tcp6 0 0 :::10050 :::* LISTEN 41194/zabbix_agentd
Nginx监控脚本
[root@localhost zabbix_agentd.d]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# cat nginx_status.sh
#!/bin/bash
if pgrep -x "nginx" > /dev/null
thenecho 0
elseecho 1
fi
[root@localhost zabbix_agentd.d]# sh nginx_status.sh
0
[root@localhost zabbix_agentd.d]#
添加自定义key配置文件
[root@localhost zabbix_agentd.d]# cat nginx_status.conf
UserParameter=nginx_status,/bin/bash /etc/zabbix/zabbix_agentd.d/nginx_status.sh
[root@localhost zabbix_agentd.d]#
zabbix-server端验证监控项
验证是否能ping通过客户端
[root@localhost ~]# zabbix_get -s 192.168.25.152 -k agent.ping
1
[root@localhost ~]#
验证监控脚本
0启动 1停止
[root@localhost ~]# zabbix_get -s 192.168.25.152 -k nginx.status
0
[root@localhost ~]#
ui界面创建Nginx监控项
设置Nginx触发器
nginx停止查看监控
[root@localhost zabbix_agentd.d]# systemctl stop nginx
[root@localhost zabbix_agentd.d]#
[root@localhost zabbix_agentd.d]# netstat -pltun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 57507/zabbix_agentd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1420/sshd: /usr/sbi
tcp6 0 0 :::10050 :::* LISTEN 57507/zabbix_agentd
tcp6 0 0 :::22 :::* LISTEN 1420/sshd: /usr/sbi
udp 0 0 127.0.0.1:323 0.0.0.0:* 691/chronyd
udp6 0 0 ::1:323 :::* 691/chronyd
[root@localhost zabbix_agentd.d]#
通过更新修改问题状态
[root@localhost zabbix_agentd.d]# systemctl start nginx
启动后nginx正常恢复