• zabbix 通过自定义key完成网卡监控


    创建执行脚本:

    # cat /etc/zabbix/monitor_scripts/network.sh 
    #!/bin/bash
    #set -x 
    usage() {
            echo "Useage : $0"
            echo "eg. sh $0 eth0"
            exit 1
    }
    if [ $# -lt 1 ]
    then
            usage
    fi
    eth=$1
    timer=1
    in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/(.*):(.*)/2/g" | awk '{print $1 }')
    out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/(.*):(.*)/2/g" | awk '{print $9 }')
    x=1
    while [ $x -le 2 ]
    do
            sleep ${timer}
            in=$(cat /proc/net/dev | grep $eth | sed -e "s/(.*):(.*)/2/g" | awk '{print $1 }')
            out=$(cat /proc/net/dev | grep $eth | sed -e "s/(.*):(.*)/2/g" | awk '{print $9 }')
            dif_in=$(((in-in_old)/timer))
            dif_in=$((dif_in/1024))
            dif_out=$(((out-out_old)/timer))
            dif_out=$((dif_out/1024))
            ct=$(date +"%F %H:%M:%S")
            echo "${ct} -- IN: ${dif_in} KByte/s     OUT: ${dif_out} KByte/s"
            in_old=${in}
            out_old=${out}
            x=3
    done
    exit 0
    
    # cat /etc/zabbix/monitor_scripts/networkin.sh 
    /etc/zabbix/monitor_scripts/network.sh eth1 |awk '{print $5}'
    
    # cat /etc/zabbix/monitor_scripts/networkout.sh 
    /etc/zabbix/monitor_scripts/network.sh eth1 |awk '{print $8}'
    

     修改配置文件,关联自定义key:

    ]# grep Include /etc/zabbix/zabbix_agentd.conf 
    ### Option: Include
    # Include=
    # Include=/etc/zabbix/zabbix_agentd.userparams.conf
    # Include=/etc/zabbix/zabbix_agentd/
    #Include=/etc/zabbix/zabbix_agentd/*.conf
    Include=/etc/zabbix/zabbix_agentd.d/
    
    
    # cat /etc/zabbix/zabbix_agentd.d/networkInOut.conf 
    UserParameter=networkin,/etc/zabbix/monitor_scripts/networkin.sh
    UserParameter=networkout,/etc/zabbix/monitor_scripts/networkout.sh
    

     增加自定义模版:Network incoming or outcoming on eth1 

    查看item:

    创建triggers:

    查看:

    创建视图展示:

    增加新建的模板并查看效果:

  • 相关阅读:
    spring-data-elasticsearch (elasticsearch 6.7.0) @Document 和 @Field 注解详解
    干货链接(大神)
    Excel word PDF导入导出 Easy POI
    helm 源大集合
    K8s学习干货
    K8S
    阳明大神---容器时代
    K8s高可用集群部署
    最小 docker_lpnm系统
    python 协程和异步编程全解
  • 原文地址:https://www.cnblogs.com/bass6/p/6894896.html
Copyright © 2020-2023  润新知