zabbix 监控nginx状态:

本文详细介绍了如何通过开启nginx_status模块监控功能、使用Zabbix脚本收集并分析Nginx状态数据,以及配置Zabbix以监控网站访问量和带宽使用情况,有效提升网站性能。

   很久没有写博客了,今天遇到个麻烦事,网站的访问量突然加大,监控报警是把我的机房带宽全部跑满了,最后把硬件防火墙的策略改动之后才恢复正常。然后负责人要关于nginx网站,和带宽的状态,于是就想起要做这个了,主要是监控nginx的一些链接状态:

1、首先开启nginx_status模块监控功能:

server {
        listen      8067;
        server_name localhost; 
        root       html; 
        index  index.html;
        access_log off;
        location /status {
          stub_status on;
        }
}

2、测试:

[root@WEB_007 vhosts]# curl http://192.168.10.7:8067/status
Active connections: 3 
server accepts handled requests
 1305214152 1305214152 1305204005 
Reading: 0 Writing: 3 Waiting: 0

3、编写脚本过滤数据:(zabbix主要有数据就能出图):

[root@WEB_007 vhosts]# cat /usr/local/zabbix/scripts/nginx_status 
#!/bin/bash  
# Script to fetch nginx statuses for tribily monitoring systems  
# Author: xiaoluo
# License: GPLv2 
 
function active {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Active' | awk '{print $NF}'  
} 
function reading {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Reading' | awk '{print $2}'  
} 
function writing {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Writing' | awk '{print $4}'  
} 
function waiting {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'  
} 
function accepts {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $1}'  
} 
function handled {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $2}'  
} 
function requests {  
/usr/bin/curl "http://192.168.10.7:8067/status" 2>/dev/null| awk NR==3 | awk '{print $3}'  
} 
# Run the requested function  
$1

4、开启zabbix脚本功能、我现在是习惯把执行的key,放在另一个路径下,以后文件多了好区分,大家应该也建议这么做:

[root@WEB_007 zabbix_agentd.conf.d]# vi /usr/local/zabbix/etc/zabbix_agentd.conf 
UnsafeUserParameters=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@WEB_007 zabbix_agentd.conf.d]#cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@WEB_007 zabbix_agentd.conf.d]#vi nginx
#monitor nginx
UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx_status $1

5、导入模板:模块在我的附件可以自己下载:

这里演示,在那个时候我第一次制作,所以忘记添加图形了,大家可以自己根据模板添加图形,还有触发器我也没有创建,大家根据自己的需要进行创建

6、图形查看效果:

wKioL1VIjw-wE_NFAAWNK4_UNvM835.jpg    总结:zabbix可以很好的根据应用来进行监控,还很强大,慢慢研究

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值