一、执行脚本创建
网卡IN流量
#vim networkin.sh
/usr/local/zabbix/bin/jichuang/network.sh eth1 | awk '{print $5}'
网卡OUT流量
#vim networkout.sh
/usr/local/zabbix/bin/jichuang/network.sh eth1 | awk '{print $8}'
二、添加执行权限
#chmod +x network networkin networkout
三、修改配置文件
#vim /usr/local/zabbix/etc/zabbix_agentd.conf
#service zabbix_agentd restart
四、服务端测试,能调用到数据
五、zabbix添加监控项。。。图形。。。
六、触发器,报警
公司外网口为速度为100M,超出90M则报警
jichuang: 模板
networkin : 调用的监控键值
92160 : 90M=92160kb
流量获取脚本:
vim network.sh
#!/bin/bash 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
转载于:https://blog.51cto.com/yangmv/1743105