zabbix自定义监控nginx状态页面
确保nginx状态界面打开
[root@nginx ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC)
built with OpenSSL 1.1.1 FIPS 11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
这里选择监控Waiting的值
[root@localhost ~]# curl -s 192.168.145.175/status |awk 'NR==4'|awk -F: {'print $4'}
0
[root@nginx ~]# yum -y install gcc gcc-c++ bzip2 pcre* make wget
[root@nginx ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.6.tar.gz
[root@nginx ~]# ls
公共 视频 文档 音乐 anaconda-ks.cfg zabbix-5.4.6.tar.gz
模板 图片 下载 桌面 initial-setup-ks.cfg zabbix-5.4.6.tar.gz.1
[root@nginx ~]# tar xf zabbix-5.4.6.tar.gz
[root@nginx ~]# tar xf zabbix-5.4.6.tar.gz
[root@nginx ~]# useradd -r -M -s /sbin/nologin zabbix
[root@nginx ~]# chown zabbix.zabbix zabbix-5.4.6
[root@nginx ~]# cd zabbix-5.4.6/
[root@nginx zabbix-5.4.6]# ./configure --enable-agent
[root@nginx zabbix-5.4.6]# make install
Server=192.168.145.170 修改成zabbix服务端IP
ServerActive=192.168.145.170 修改成zabbix服务端IP
Hostname=nginx 主机名
UnsafeUserParameters=1
UserParameter=status,/scripts/status.sh 添加这行指明脚本位置
编写监控脚本
[root@nginx ~]# mkdir /scripts
[root@nginx ~]# cd /scripts/
[root@nginx scripts]# vim status.sh
[root@nginx scripts]# cat status.sh
#!/bin/bash
status=$(curl -s 192.168.145.175/status |awk 'NR==4'|awk -F: {'print $4'})
if [ $status -ge 1 ];then
echo "1"
else
echo "0"
fi
[root@nginx scripts]# chmod +x status.sh
[root@nginx scripts]# ls
status.sh
开启服务
[root@nginx ~]# zabbix_agentd
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::]:111 [::]:*
[root@localhost ~]# zabbix_get -s 192.168.145.175 -k status
0
[root@localhost ~]# zabbix_get -s 192.168.145.175 -k status 1