腳本經過snmp信息獲取接口流量bash
注:使用cacti對設備接口採集流量時,若是設備的snmp使用的是v1版本,則只會生成rrd文件,而始終沒有數據;改用snmp v2版本後,立刻可以收到數據,並畫出圖形!!緣由未知!!!ide
eth0_traffic.shspa
=================================================================pwa
#!/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)get
eth0_in=$(snmpget -v 1 -c public -IR -Os 127.0.0.1 ifInOctets.${index}|cut -d ':' -f 2|tr -d '[:blank:]')it
eth0_out=$(snmpget -v 1 -c public -IR -Os 127.0.0.1 ifOutOctets.${index}|cut -d ':' -f 2|tr -d '[:blank:]')class
echo $eth0_insed
echo $eth0_outgrep
====================================================
[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,求當前值;