zabbix监控Nginx状态界面

1、开启状态界面

实例:
开启status:

location /status {
  stub_status {on | off};
  allow 172.16.0.0/16;
  deny all;
}

访问状态页面的方式:http://server_ip/status

状态页面信息详解:

状态码表示的意义
Active connections 2当前所有处于打开状态的连接数
accepts总共处理了多少个连接
handled成功创建多少握手
requests总共处理了多少个请求
Readingnginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writingnginx返回给客户端的Header信息数,表示请求已经接收完成,
且正处于处理请求或发送响应的过程中的连接数
Waiting开启keep-alive的情况下,这个值等于active - (reading + writing),
意思就是Nginx已处理完正在等候下一次请求指令的驻留连接

监控nginx状态界面

主机作用ip
zabbix服务端192.168.2.129
nginx+zabbix客户端192.168.2.128
[root@localhost conf]# vim nginx.conf
location /nginx_status {
            stub_status on;
        }
[root@localhost conf]# systemctl restart nginx.service 

192.168.2.128/nginx_status访问

[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf  //添加下面三行
Server=192.168.2.129     //服务端ip
ServerActive=192.168.2.129  //服务端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.2.128 -k check_nginx[active]   //修改中括号内想要查看的状态名称即可
3
[root@zabbix ~]# zabbix_get -s 192.168.2.128 -k check_nginx[accepts]
19
[root@zabbix ~]# zabbix_get -s 192.168.2.128 -k check_nginx[handled]
20

web界面配置
创建监控主机


配置监控项

 创建组(需要监控其他状态添加进去即可)

 监控组

 添加完成后就能看总共处理了多少个连接的状态

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值