Zabbix监控Nginx的status

Zabbix监控Nginx的status


部署Zabbix监控Nginx的status

环境说明:

主机名IP服务系统
zabbix192.168.188.130zabbixcentos8
nginx192.168.188.128nginx
zabbix_agentd
centos8

部署zabbix不作演示,请参考此篇博客👉部署zabbix监控服务

nginx开启状态页面

nginx能开启状态页面的前提是安装了这个模块,你可以nginx -V查看一下编译参数里有无--with-http_stub_status_module

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
......        
            location = /status {
            stub_status;
            allow 127.0.0.1;     #允许本机访问
            allow 192.168.188.1;                #允许真实本机访问
            deny all;                   #拒绝所有其它的主机
        }
.......
[root@nginx ~]# systemctl restart nginx.service

验证是否能访问,不能访问则无法监控状态

[root@nginx ~]# curl http://127.0.0.1/status
Active connections: 1
server accepts handled requests
 1 1 1
Reading: 0 Writing: 1 Waiting: 0

去浏览器验证真实本机是否能访问

在这里插入图片描述

在nginx服务器安装zabbix_agentd并配置监控脚本

安装zabbix_agentd

#新增zabbix用户
[root@nginx ~]# useradd -rMs /sbin/nologin zabbix

#安装依赖包
[root@nginx ~]# dnf -y install make gcc gcc-c++ pcre-devel openssl openssl-devel wget

#下载zabbix并解压
[root@nginx ~]# cd /usr/local/src/
[root@nginx src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.3.tar.gz
[root@nginx src]# tar -xf zabbix-6.2.3.tar.gz

#编译安装zabbix_agentd
[root@nginx src]# cd zabbix-6.2.3/
[root@nginx zabbix-6.2.3]# ./configure --enable-agent
......
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************
[root@nginx zabbix-6.2.3]# make install

#连接到zabbix服务端
[root@nginx zabbix-6.2.3]# cd /usr/local/etc/
[root@nginx etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d
[root@nginx etc]# vim zabbix_agentd.conf
.......................
Server=192.168.188.130		#填写zabbix服务端的IP地址
.......................
ServerActive=192.168.188.130		#填写zabbix服务端的IP地址
.......................
Hostname=nginx		#该主机可自定义,但要全局唯一。在web管理界面中添加主机要用到该主机名,两边须一致方可识别
.......................

#启动zabbix_agentd
[root@nginx etc]# zabbix_agentd
[root@nginx etc]# ss -anlt | grep 10050
LISTEN 0      128          0.0.0.0:10050      0.0.0.0:*

编写并配置监控脚本

#编写监控脚本
[root@nginx ~]# mkdir /scripts
[root@nginx ~]# cd /scripts
[root@nginx scripts]# vim nginx_status.sh
#!/bin/bash

case $1 in
    Reading)
        curl -s 127.0.0.1/status |awk "NR==4{print\$2}"
        ;;
    Writing)
        curl -s 127.0.0.1/status |awk "NR==4{print\$4}"
        ;;
    Waiting)
        curl -s 127.0.0.1/status |awk "NR==4{print\$6}"
    ;;
    *)
        exit
        ;;
esac
[root@nginx scripts]# chmod +x nginx_status.sh

#配置监控脚本
[root@nginx scripts]# vim /usr/local/etc/zabbix_agentd.conf
.............
UnsafeUserParameters=1
UserParameter=nginx_status[*],/bin/bash /scripts/nginx_status.sh $1
[root@nginx scripts]# pkill zabbix_agentd
[root@nginx scripts]# zabbix_agentd

#去zabbix服务端检查key是否可用
[root@zabbix-server ~]# zabbix_get -s 192.168.188.128 -k nginx_status[Waiting]
0

在zabbix的Web界面配置监控nginx

添加主机

在这里插入图片描述
添加监控项

监控Reading

在这里插入图片描述
监控Writing

在这里插入图片描述
监控Waiting

在这里插入图片描述
在这里插入图片描述
查看是否有监控返回的值,有值则说明监控成功了

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
添加触发器
在企业中要视具体服务器情况而作配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随便投投

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值