zabbix监控nginx状态页面

1. 监控nginx驻留连接数

在这里插入图片描述

[root@nginx scripts]# curl -s 192.168.8.137/status
Active connections: 1 
server accepts handled requests
 234 234 281 
Reading: 0 Writing: 1 Waiting: 0 
[root@nginx scripts]# 

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

环境说明:

系统平台IP需要安装的服务
rhel-8.2192.168.8.130(zabbix)lamp
zabbix_server
zabbix_agent
rhel-8.2192.168.8.137(nginx)nginx
zabbix_agent

2. 修改被监控机的配置文件

[root@nginx scripts]# vim /usr/local/etc/zabbix_agentd.conf
322 UnsafeUserParameters=1   //取消注释修改为1
525 UserParameter=check_status,/scripts/check_status.sh   //在配置文件最后添加
//重启服务
[root@nginx scripts]# pkill zabbix_agentd 
[root@nginx scripts]# zabbix_agentd 

3. 写脚本,脚本放到统一的位置


[root@nginx scripts]# cat check_status.sh 
#!/bin/bash

count=$(curl -s 192.168.8.137/status |awk 'NR==4'|awk -F: {'print $4'})   //利用awk命令打印第四行第四个

if [ $count -gt 2 ];then   //如果大于2,输出为1否则输出为0
    echo "1"
else
    echo "0"
fi
[root@nginx scripts]# 
//手动验证脚本
[root@nginx scripts]# bash -x check_status.sh 
++ curl -s 192.168.8.137/status
++ awk NR==4
++ awk -F: '{print $4}'
+ count=' 0 '
+ '[' 0 -gt 2 ']'
+ echo 0
0
[root@nginx scripts]# 

//zabbix-server端测试是否有问题
[root@zabbix ~]# zabbix_get -s 192.168.8.137 -k check_status
0
[root@zabbix ~]# 

//模拟故障
[root@nginx scripts]# curl -s 192.168.8.137/status
Active connections: 4 
server accepts handled requests
 123 123 137 
Reading: 0 Writing: 1 Waiting: 3 
[root@zabbix ~]# zabbix_get -s 192.168.8.137 -k check_status
1
[root@zabbix ~]# 

4. 在web界面配置监控项和触发器

创建主机组
在这里插入图片描述
创建主机,并添加到主机组
在这里插入图片描述
创建监控项
在这里插入图片描述
在这里插入图片描述
查看最新数据
在这里插入图片描述
添加触发器
在这里插入图片描述

在这里插入图片描述

//模拟故障
[root@nginx scripts]# curl -s 192.168.8.137/status
Active connections: 5 
server accepts handled requests
 209 209 256 
Reading: 0 Writing: 1 Waiting: 4 
[root@nginx scripts]# 

在这里插入图片描述

//恢复正常
[root@nginx scripts]# curl -s 192.168.8.137/status
Active connections: 1 
server accepts handled requests
 212 212 259 
Reading: 0 Writing: 1 Waiting: 0 
[root@nginx scripts]# 

在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

彭宇栋

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

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

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

打赏作者

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

抵扣说明:

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

余额充值