栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

zabbix自定义监控nginx状态页面

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zabbix自定义监控nginx状态页面

文章目录
  • 1.环境
  • 2.确保nginx状态界面打开
  • 3. 在nginx端编写脚本来监控nginx端的状态页面
    • 3.1 配置从机上的zabbix_agent
    • 3.2 关闭两端的防火墙和selinux
  • 4. web界面配置

1.环境
主机名IP安装的服务
zabbix192.168.216.188zabbix-server zabbix-agentd
nginx192.168.216.215nginx zabbix-agentd
2.确保nginx状态界面打开
[root@nginx ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
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
// --with-http_stub_status_module为状态界面的模块

修改配置文件见往期文章点此

确保能看到这个页面

3. 在nginx端编写脚本来监控nginx端的状态页面
//这里选择监控Waiting的值
[root@nginx ~]# curl -s 192.168.216.215/status |awk 'NR==4'|awk -F: {'print $4'}
 0 
3.1 配置从机上的zabbix_agent
//安装zabbix_agent
[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 ~]# 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 ~]# 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

//修改配置文件
[root@nginx ~]# vim /usr/local/etc/zabbix_agentd.conf
······
Server=192.168.216.188	#修改成zabbix服务端IP
······
ServerActive=192.168.216.188 #修改成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]# chmod +x status.sh 
[root@nginx scripts]# cat status.sh 
#!/bin/bash

status=$(curl -s 192.168.216.215/status |awk 'NR==4'|awk -F: {'print $4'})

if [ $status -ge 1 ];then
    echo "1"     //如果驻留连接大于等于1就触发报警
else
    echo "0"
fi
//开启zabbix
[root@nginx ~]# zabbix_agentd 
[root@nginx ~]# ss -antl
State      Recv-Q Send-Q                                                   Local Address:Port                                                                  Peer Address:Port              
LISTEN     0      128                                                                  *:10050                                                                            *:*                  
LISTEN     0      128                                                                  *:80                                                                               *:*                  
LISTEN     0      128                                                                  *:22                                                                               *:*                  
LISTEN     0      100                                                          127.0.0.1:25                                                                               *:*                  
LISTEN     0      128                                                                  *:443                                                                              *:*                  
LISTEN     0      128                                                                 :::22                                                                              :::*                  
LISTEN     0      100                                                                ::1:25                                                                              :::*    

//zabbix端测试是否有问题  
[root@zabbix ~]# zabbix_get -s 192.168.216.215 -k status   
0
//去网页访问,出现变化
[root@zabbix ~]# zabbix_get -s 192.168.216.215 -k status   
1

3.2 关闭两端的防火墙和selinux

4. web界面配置






同样的办法添加触发器


访问nginx端手动触发

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361561.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号