Zabbix 监控 Nginx 当前的活动连接数
前言
本环境是基于 Centos 7.8 系统构建 Zabbix 学习环境
安装 Zabbix-4.4.10 具体参考:Zabbix-4.4.10 环境部署
一、zabbix-agent 配置
部署 nginx
# 部署 nginx
[root@linux-rhel-7 ~]# yum install nginx -y
修改 nginx 配置文件
[root@linux-rhel-7 ~]# vim /etc/nginx/nginx.conf
... ...
location /status {
stub_status on;
access_log off;
allow 192.168.5.0/24;
deny all;
}
... ...
[root@linux-rhel-7 ~]# systemctl restart nginx
编写监控脚本
[root@linux-rhel-7 ~]# vim /scripts/check_nginx.sh
#!/bin/bash
HOST=192.168.5.12
PORT="80"
# 检测 nginx 进程是否存在
function ping {
/sbin/pidof nginx | wc -l
}
# 检测 nginx 性能
function active {
/usr/bin/curl -s http://$HOST/status | awk '/Active/ {print $3}'
}
function reading {
/usr/bin/curl -s http://$HOST/status | awk '/Reading/ {print $2}'
}
function writing {
/usr/bin/curl -s http://$HOST/status | awk '/Writing/ {print $4}'
}
function waiting {
/usr/bin/curl -s http://$HOST/status | awk '/Waiting/ {print $6}'
}
function accepts {
/usr/bin/curl -s http://$HOST/status | awk 'NR==3 {print $1}'
}
function handled {
/usr/bin/curl -s http://$HOST/status | awk 'NR==3 {print $2}'
}
function requests {
/usr/bin/curl -s http://$HOST/status | awk 'NR==3 {print $3}'
}
$1
[root@linux-rhel-7 ~]# chmod +x /scripts/check_nginx.sh
修改 zabbix-server 配置文件
[root@linux-rhel-7 ~]# vim /etc/zabbix/zabbix_agentd.d/UserParameter_nginx.conf
UserParameter=nginx.status[*], /scripts/check_nginx.sh $1
[root@linux-rhel-7 ~]# systemctl restart zabbix-agent.service
二、zabbix-server 配置
浏览器登录:http://192.168.5.11/zabbix
导入nginx监控模板
选择导入的模板
三、采集数据
多次高并发访问 nginx
[root@zabbix-server ~]# ab -c 1000 -n 1000000 http://192.168.5.12/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.5.12 (be patient)
apr_socket_recv: Connection timed out (110)
Total of 18405 requests completed
[root@zabbix-server ~]# ab -c 1000 -n 1000000 http://192.168.5.12/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.5.12 (be patient)
apr_socket_recv: Connection timed out (110)
Total of 19435 requests completed
[root@zabbix-server ~]# ab -c 1000 -n 1000000 http://192.168.5.12/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.5.12 (be patient)
apr_socket_recv: Connection timed out (110)
Total of 19407 requests completed
[root@zabbix-server ~]#
查看监控数据
创建聚合图形
聚合图形展示