文章目录
开启状态界面
实例:
开启status:
location /status {
stub_status {on | off};
allow 172.16.0.0/16;
deny all;
}
访问状态页面的方式:http://server_ip/status
状态页面信息详解:
监控nginx状态界面
主机作用 | ip |
---|---|
zabbix服务端 | 192.168.220.20 |
nginx+zabbix客户端 | 192.168.220.10 |
[root@localhost conf]# vim nginx.conf
location /nginx_status {
stub_status on;
}
[root@localhost conf]# systemctl restart nginx.service
浏览器访问
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf //添加下面三行
Server=192.168.220.20 //服务端ip
ServerActive=192.168.220.20 //服务端ip
Hostname=test //必须唯一
编写脚本
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# vim check_nginx.sh
[root@localhost scripts]# cat check_nginx.sh
#Script to fetch nginx statuses for monitoring systems
HOST="127.0.0.1"
PORT="80"
function ping {
/sbin/pidof nginx | wc -l
}
function active {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
$1
[root@localhost scripts]# chmod +x /scripts/check_nginx.sh
开启自定义监控
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1 //取消注释 修改为1
UserParameter=check_nginx[*],/bin/bash /scripts/check_nginx.sh $1 //最后添加
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
服务端测试
[root@zabbix ~]# zabbix_get -s 192.168.220.10 -k check_nginx[active] //修改中括号内想要查看的状态名称即可
3
[root@zabbix ~]# zabbix_get -s 192.168.220.10 -k check_nginx[accepts]
19
[root@zabbix ~]# zabbix_get -s 192.168.220.10 -k check_nginx[handled]
20
web界面配置
创建监控主机
配置监控项
创建组(需要监控其他状态添加进去即可)
监控组
添加完成后就能看总共处理了多少个连接的状态