zabbix监控nginx状态界面
目录
环境说明:
主机名 | 主机作用 | ip |
---|---|---|
zabbix | zabbix服务端 | 192.168.226.132 |
nginx | nginx+zabbix客户端 | 192.168.226.138 |
1. 开启状态界面
nginx主机开启status:
location /status {
stub_status on;
}
**访问状态页面的方式:**http://server_ip/status
Active connections: 2
server accepts handled requests
2 2 1
Reading: 0 Writing: 1 Waiting: 1
状态页面信息详解:
状态码 | 表示的意义 |
---|---|
Active connections 2 | 当前所有处于打开状态的连接数 |
accepts | 总共处理了多少个连接 |
handled | 成功创建多少握手 |
requests | 总共处理了多少个请求 |
Reading | nginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数 |
Writing | nginx返回给客户端的Header信息数,表示请求已经接收完成, 且正处于处理请求或发送响应的过程中的连接数 |
Waiting | 开启keep-alive的情况下,这个值等于active - (reading + writing), 意思就是Nginx已处理完正在等候下一次请求指令的驻留连接 |
2. nginx主机配置
[root@nginx ~]# vim /usr/local/etc/zabbix_agentd.conf
.......
# zabbix-server端的ip地址
Server=192.168.226.132
ServerActive=192.168.226.132
# zabbix-agent端的主机名
Hostname=nginx
#自定义监控打开,创建自定义监控任务
#check_status[*]对应web监控项 <key>
#$1 对应 web界面配置监控项 配key时[]中的内容
UnsafeUserParameters=1
UserParameter=check_status[*],/bin/bash /scripts/nginx_status.sh $1
.......
3. nginx主机上脚本
[root@nginx ~]# mkdir /scripts
[root@nginx ~]# vim /scripts/nginx_status.sh
case $1 in
"reading")
curl -s http://192.168.226.138/status | awk 'NR==4{print $2}'
;;
"writing")
curl -s http://192.168.226.138/status | awk 'NR==4{print $4}'
;;
"waiting")
curl -s http://192.168.226.138/status | awk 'NR==4{print $6}'
;;
esac
[root@nginx ~]# chown -R zabbix:zabbix /scripts
[root@nginx ~]# ll /scripts
total 4
-rwxr-xr-x 1 zabbix zabbix 286 Oct 20 10:41 nginx_status.sh
4. zabbix主机测试
[root@zabbix ~]# zabbix_get -s 192.168.226.138 -k check_status[writing]
1
5. zabbix的web界面配置
5.1创建监控主机
5.2创建监控项
5.3添加触发器
5.4测试
测试前,无驻留连接
[root@nginx scripts]# curl 192.168.226.138/status
Active connections: 1
server accepts handled requests
97 97 144
Reading: 0 Writing: 1 Waiting: 0
测试后,驻留连接大于3,警报
[root@nginx ~]# curl 192.168.226.138/status
Active connections: 5
server accepts handled requests
111 111 199
Reading: 0 Writing: 1 Waiting: 4