zabbix监控nginx状态

zabbix监控nginx状态

服务端客户端
主机名C1C2
ip192.168.207.143192.168.207.131

启动nginx

[root@localhost ~]# nginx
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:80                0.0.0.0:*                  
LISTEN    0         128                   [::]:22                   [::]:*  

配置nginx

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location /nginx_status {
            stub_status on;
            access_log off;
            allow 127.0.0.1;
            allow 192.168.207.1;
            deny all;
        }
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload

image-20210627131532505

编写脚本

[root@localhost ~]# vim /scripts/check_nginx.sh
#!/bin/bash
#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 ~]# chmod +x /scripts/check_nginx.sh

在要监控的主机上安装agent

[root@localhost ~]# ls
anaconda-ks.cfg  zabbix-5.2.6.tar.gz
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv zabbix-5.2.6/ zabbix
[root@localhost local]# yum -y install gcc gc++ make pcre*
[root@localhost local]# cd zabbix/
[root@localhost zabbix]# ./configure --enable-agent
[root@localhost zabbix]# make install
[root@localhost zabbix]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:10050             0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:80                0.0.0.0:*                  
LISTEN    0         128                   [::]:22                   [::]:*   

在agentd. conf文件中配置server地址和hostname启动agent

[root@localhost zabbix]# vim /usr/local/etc/zabbix_agentd.conf
Server=192.168.207.143    
ServerActive=192.168.207.143
Hostname=Zabbix123

重启服务

[root@localhost zabbix]# pkill zabbix_agentd 
[root@localhost zabbix]# zabbix_agentd 

zabbix-agent配置文件开启自定义功能

[root@localhost zabbix]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1   #取消注释并改为1
UserParameter=check_nginx[*],/bin/bash /scripts/check_nginx.sh $1 添加在最后的空白处

测试server端是否可以收到数据

[root@localhost etc]# zabbix_get -s 192.168.207.131 -p 10050 -k check_nginx[accepts]
9
[root@localhost etc]# zabbix_get -s 192.168.207.131 -k check_nginx[active]
1

在web上添加监控项

image-20210627134755959

image-20210627134848514

image-20210627134912995

image-20210627134934923

image-20210627135536925

image-20210627135519636

image-20210627135653153

继续改参数

image-20210627135913592

image-20210627135932003

image-20210627135945806

image-20210627140001090

image-20210627140652991

image-20210627140347712

image-20210627140457212

image-20210627141223580

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值