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 | 总共处理了多少个请求 |
Reading | nginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数 |
Writing | nginx返回给客户端的Header信息数,表示请求已经接收完成, 且正处于处理请求或发送响应的过程中的连接数 |
Waiting | 开启keep-alive的情况下,这个值等于active - (reading + writing), 意思就是Nginx已处理完正在等候下一次请求指令的驻留连接 |
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
rhel-8.2 | 192.168.8.130(zabbix) | lamp zabbix_server zabbix_agent |
rhel-8.2 | 192.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]#