监控案例实战 -- 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 ~]# 

查看监控数据
在这里插入图片描述
在这里插入图片描述
创建聚合图形
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
聚合图形展示
在这里插入图片描述

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值