zoukankan      html  css  js  c++  java
  • 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:

    查看:

    创建视图展示:

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

  • 相关阅读:
    ubuntu 12.04(Precise Pangolin)启用休眠(Hibernate)功能的方案
    svn小技巧——重定向svn diff
    引用对象深度复制
    引用对象深度复制的简单实现方法
    vue Excel导出 [post请求+提示语]
    随手笔记-二进制的正负计算
    枚举类的扩展使用
    关于担心java import xxx.*对资源占用的一次小实践
    idea 自动添加注释 (方法+类 带参数/返回值)
    maven打包到本地仓库
  • 原文地址:https://www.cnblogs.com/bass6/p/6894896.html
Copyright © 2011-2022 走看看