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:
查看:
创建视图展示:
增加新建的模板并查看效果:
联系方式QQ:326528263 EMAIL:clnking@163.com 网名:bass 分享技术 突破难点 创新思维