一、conf文件
UserParameter=traffic_hour.rx,/bin/sh /usr/local/zabbix/etc/zabbix_agentd.conf.d/vnstat.sh h r
UserParameter=traffic_hour.tx,/bin/sh /usr/local/zabbix/etc/zabbix_agentd.conf.d/vnstat.sh h t
UserParameter=traffic_day.rx,/bin/sh /usr/local/zabbix/etc/zabbix_agentd.conf.d/vnstat.sh d r
UserParameter=traffic_day.tx,/bin/sh /usr/local/zabbix/etc/zabbix_agentd.conf.d/vnstat.sh d t
二、监控项脚本
#!/bin/sh
if [[ $1 = h && $2 = t ]]; then
vnstat -h |tail -n 2 |head -n 1 |awk '{print $9}'
fi
if [[ $1 = h && $2 = r ]]; then
vnstat -h |tail -n 2 |head -n 1 |awk '{print $8}'
fi
if [[ $1 = d && $2 = t ]]; then
DANWEI=`vnstat -d | tail -n 4 |head -n 1 | awk -F '|' '{print $2}' |awk '{print $2}'`
SHU=`vnstat -d | tail -n 4 |head -n 1 | awk -F '|' '{print $2}' |awk '{print $1}'|sed "s/' '//g"`
if [ $DANWEI = TiB ]; then
SHU=`echo "$SHU 1024" |awk '{printf("%.2f", $1*$2)}'`
fi
echo $SHU
fi
if [[ $1 = d && $2 = r ]]; then
DANWEI=`vnstat -d | tail -n 4 |head -n 1 | awk -F '|' '{print $1}' |awk '{print $3}'`
SHU=`vnstat -d | tail -n 4 |head -n 1 | awk -F '|' '{print $1}' |awk '{print $2}'|sed "s/' '//g"`
if [ $DANWEI = TiB ]; then
SHU=`echo "$SHU 1024" |awk '{printf("%.2f", $1*$2)}'`
fi
echo $SHU
fi
三、配置监控项