创建执行脚本:
# 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 usagefieth=$1timer=1in_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=1while [ $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=3doneexit 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/*.confInclude=/etc/zabbix/zabbix_agentd.d/# cat /etc/zabbix/zabbix_agentd.d/networkInOut.conf UserParameter=networkin,/etc/zabbix/monitor_scripts/networkin.shUserParameter=networkout,/etc/zabbix/monitor_scripts/networkout.sh
增加自定义模版:Network incoming or outcoming on eth1
查看item:
创建triggers:
查看:
创建视图展示:
增加新建的模板并查看效果: