脚本通过snmp信息获取接口流量
注:使用cacti对设备接口采集流量时,如果设备的snmp使用的是v1版本,则只会生成rrd文件,而始终没有数据;改用snmp v2版本后,马上能够收到数据,并画出图形!!原因未知!!!
eth0_traffic.sh
=================================================================
#!/bin/bash
index=$(snmpwalk -v 1 -c public -IR 127.0.0.1 RFC1213-MIB::ifDescr |grep eth0|cut -d '=' -f 1|cut -d '.' -f 2)
eth0_in=$(snmpget -v 1 -c public -IR -Os 127.0.0.1 ifInOctets.${index}|cut -d ':' -f 2|tr -d '[:blank:]')
eth0_out=$(snmpget -v 1 -c public -IR -Os 127.0.0.1 ifOutOctets.${index}|cut -d ':' -f 2|tr -d '[:blank:]')
echo $eth0_in
echo $eth0_out
====================================================
[root@Cnyunwei tmp]# sh eth0_traffic.sh
1481808
6200370
=====================================
利用snmp来获取网卡的流量:
snmpwalk -v 1 -c public 1.1.1.1 ifInOctets.2 | sed -e 's/.*ter32: \(.*\)/\1/'
==================================================
“天”这笔表采用的是-r 300,求出最大值;
“星期”这张表采用的是-r 1800,求出最大值;
“月”这张表采用的是-r 7200,求出最大值;
“年”这张表采用的是-r 86400,求当前值;
转载于:https://blog.51cto.com/cvgcv6666/1677765