0
点赞
收藏
分享

微信扫一扫

zabbix Nginx_low_discover监控设置

Ewall_熊猫 2022-02-10 阅读 58

首先nginx主动发现的脚本

#cat Nginx_low_discovery.sh
#!/bin/bash
# Fucation: nginx low-level discovery
# Script_name nginx_low_discovery.sh
nginx() {
            #list=`/bin/netstat  -tulnp|grep nginx|awk '{print $4}'|awk -F: '{print $2}'`
            list=`grep -wr "listen" /soft/openresty/nginx/conf/*/*.conf|grep -v '#'|awk '{print $NF}'|sort -u|grep [0-9]|sed 's/;//g'`
            tail_line=`echo $list|awk '{print $NF}'`
            printf '{\n'
            printf '\t"data":[\n'
            for key in $list
                   do
                          printf '\t {\n'
                          if [ "$key" != "$tail_line" ];then
                            printf "\t\t\t\"{#NGINXPORT}\":\"${key}\"},\n"
                          else
                            printf "\t\t\t\"{#NGINXPORT}\":\"${key}\"}\n"
                          fi
               done
                          printf '\t ]\n'
                          printf '}\n'
}
$1

第二步zabbix的配置文件

#cat userparameter_nginx.conf 
UserParameter=nginx_port.discovery[*], sh /etc/zabbix/zabbix_scripts/Nginx_low_discovery.sh $1
UserParameter=nginx.status[*], /etc/zabbix/zabbix_scripts/nginx_status.sh $1

第三步,zabbix控制台设置

  • Name NGINX Port Discovery
  • type zabbix agent(active)
  • Key nginx_port.discovery[nginx]
  • Update interval 1m
  • Keep lost resources period 7d
    Description
  • Enabled yes


接下来Item prototypes

Trigger prototypes

Graph prototypes

最后加入机器就可以了

PS:机器上加入zabbix用户sudo的权限

#cat /etc/sudoers
zabbix ALL=(root) NOPASSWD:/usr/bin/netstat,/usr/bin/ps
zabbix ALL=(ALL:ALL) NOPASSWD: /soft/nodejs/bin/pm2-zabbix
举报

相关推荐

0 条评论