首页 > 服务器维护 > nginx

zabbix自定义监控nginx状态实现过程

发布时间:2021-10-30 12:00 作者:linlusama

zabbix自定义监控nginx状态

zabbix_server 192.168.200.145
zabbix_agentd ,nginx 192.168.200.146

1. 开启状态界面

开启status:

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location /status {
     stub_status on;
     allow 192.168.200.146;
     allow 192.168.200.145
     deny all;
}
[root@localhost ~]# nginx -s reload 

在这里插入图片描述

状态页面信息详解:

状态码 表示的意义
Active connections 2 当前所有处于打开状态的连接
accepts 总共处理了多少个连接
handled 成功创建多少握手
requests 总共处理了多少个请求
Reading nginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writing nginx返回给客户端的Header信息数,表示请求已经接收完成,且正处于处理请求或发送响应的过程中的连接数
Waiting 开启keep-alive的情况下,这个值等于active - (reading + writing),意思就是Nginx已处理完正在等候下一次请求指令的驻留连接

2. 写监控脚本

[root@localhost scripts]# vim check_status.sh
#! /bin/bash
ip=$(ip a | grep 'inet ' | grep -v '127.0.0.1' | awk -F'[ /]+' '{print $3}')
case $1 in
    "Reading")
    curl -s http://$ip | awk 'NR==4 {print $2}';;
    "Writing")
    curl -s http://$ip | awk 'NR==4 {print $4}';;
    "Waiting")
    curl -s http://$ip | awk 'NR==4 {print $6}'
esac

//添加配置文件
[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_status[*],/bin/bash /scripts/check_Reading.sh $1
[root@localhost scripts]# pkill zabbix_agentd 
[root@localhost scripts]# zabbix_agentd 

//测试
[root@zabbix ~]# zabbix_get -s 192.168.200.146 -k check_status Waiting
1

3. 配置监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4. 配置触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

5. 测试

[root@localhost scripts]# ab -n 1500000 http://192.168.200.146/status

在这里插入图片描述

以上就是zabbix自定义监控nginx状态实现过程的详细内容,更多关于zabbix自定义监控nginx的资料请关注猪先飞其它相关文章!

原文出处:https://blog.csdn.net/weixin_46634416/article/details/121011

标签:[!--infotagslink--]

您可能感兴趣的文章: