zabbix监控nginx状态,显示状态active,accepts,handled,requests

zabbix监控nginx状态,显示状态active,accepts,handled,requests

一、
首先,zabbix server部署完成,可用。
接上篇zabbix部署文章,我这里zabbix server主机为:172.18.1.14
确保可以正常访问。
在这里插入图片描述
nginx主机为:172.18.8.5,确保主机安装了nginx服务,可用。
在这里插入图片描述
开启被监控端nginx状态模块。

[root@k8smaster2 nginx-1.8.1]# ./configure --help |grep statu
  --with-http_stub_status_module     enable ngx_http_stub_status_module
[root@k8smaster2 nginx-1.8.1]# 
[root@k8smaster2 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
[root@k8smaster2 nginx-1.8.1]# make

配置nginx.conf,启用status

vim /usr/local/nginx/conf/nginx.conf
#增加一个location
location /status {
        stub_status;
        }
/usr/local/nginx/sbin/nginx -s reload

确认可以拿到nginx状态

[root@k8smaster2 ~]# curl 172.18.8.5/status
Active connections: 1 
server accepts handled requests
 2 2 2 
Reading: 0 Writing: 1 Waiting: 0 
[root@k8smaster2 ~]# curl 172.18.8.5/status | awk 'NR==1{print $NF}'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    97  100    97    0     0   157k      0 --:--:-- --:--:-- --:--:-- 97000
1
[root@k8smaster2 ~]# curl -s 172.18.8.5/status | awk 'NR==1{print $NF}'
1
[root@k8smaster2 ~]# 

接下来,nginx主机上安装zabbix-agent服务。

yum install zabbix40-agent -y

配置zabbix_agent.conf

vim /etc/zabbix/zabbix_agentd.conf
#指定server和hostname
Server 172.18.1.14
Hostname= nginx
[root@k8smaster2 ~]# egrep -v "(^$|^#)" /etc/zabbix/zabbix_agentd.conf 
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.18.1.14
ServerActive=172.18.8.14
Hostname=nginx
[root@k8smaster2 ~]# 

然后创建一个nginx状态的脚本

[root@k8smaster2 src]# ls
debug  kernels  nginx-1.8.1  nginx-1.8.1.tar.gz  nginx_status.sh
[root@k8smaster2 src]# cat nginx_status.sh 
#!/bin/bash
#######################
function active {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==1{print $NF}'
}

function accepts {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==3{print $1}'
}
function handled {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==3{print $2}'
}
function requests {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==3{print $3}'
}
function reading {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==4{print $2}'
}
function writing {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==4{print $4}'
}
function waiting {
curl 172.18.8.5/status 2>/dev/null | awk 'NR==4{print $NF}'
}
$1
[root@k8smaster2 src]# 

配置zabbix-agent,在用户自定义项中增加脚本路径,以及获取值的方法,来获取脚本值:

UserParameter=nginx.status[*],bash /usr/src/nginx_status.sh $1

在这里插入图片描述
在zabbix server确认,是否可以拿到脚本结果
只有拿到脚本执行结果,才能再zabbix web中配置。

[root@zabbix-server ~]#  zabbix_get -s 172.18.8.5 -k "nginx.status[active]"
1
[root@zabbix-server ~]#  zabbix_get -s 172.18.8.5 -k "nginx.status[accepts]"
195
[root@zabbix-server ~]#  zabbix_get -s 172.18.8.5 -k "nginx.status[handled]"
196
[root@zabbix-server ~]#  zabbix_get -s 172.18.8.5 -k "nginx.status[requests]"
225
[root@zabbix-server ~]# 

WEB登录zabbix,配置主机,监控项
在这里插入图片描述
主机创建完成后,由于没有创建监控项,状态栏是灰色。
在这里插入图片描述
创建监控项
在这里插入图片描述
可以看到,此时状态栏显示绿色,可用。
在这里插入图片描述
在这里插入图片描述

可以看到有数据进来,到这里说明配置没有问题。
在这里插入图片描述
在这里插入图片描述
这样就可以实时监控nginx状态信息了。

如果nginx服务停止了,能否通知管理员呢?zabbix也是可以的,这就需要触发器与动作了。下篇会详细介绍这部分。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿蔡BLOG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值