有些網路設備不提供即時頻寬,只好學Mrtg抓標準的snmp oid,再計算出當時使用頻寬..
以下範例是抓取 switch的port 48 ,ifspeed(port速率是100Mb),抓取間隔為60秒
tmp_port6_in=`/usr/bin/snmpwalk -v 2c -c public 10.110.1.252 1.3.6.1.2.1.2.2.1.10.48 | awk {'print $4'}`
old_port6_in=`cat /tmp/old_port6_in`
port6_in=`/usr/bin/expr \( $tmp_port6_in - $old_port6_in \) \* 8 / 60 /1000000`
echo $tmp_port6_in > /tmp/old_port6_in
tmp_port6_ou=`/usr/bin/snmpwalk -v 2c -c public 10.110.1.252 1.3.6.1.2.1.2.2.1.16.48 | awk {'print $4'}`
old_port6_ou=`cat /tmp/old_port6_ou`
port6_ou=`/usr/bin/expr \( $tmp_port6_ou - $old_port6_ou \) \* 8 / 60 /1000000`
echo $tmp_port6_ou > /tmp/old_port6_ou
記得再rc.local 加echo 0 > /tmp/old_port6_in 和 /tmp/old_port6_out 以下範例是抓取 switch的port 48 ,ifspeed(port速率是100Mb),抓取間隔為60秒
tmp_port6_in=`/usr/bin/snmpwalk -v 2c -c public 10.110.1.252 1.3.6.1.2.1.2.2.1.10.48 | awk {'print $4'}`
old_port6_in=`cat /tmp/old_port6_in`
port6_in=`/usr/bin/expr \( $tmp_port6_in - $old_port6_in \) \* 8 / 60 /1000000`
echo $tmp_port6_in > /tmp/old_port6_in
tmp_port6_ou=`/usr/bin/snmpwalk -v 2c -c public 10.110.1.252 1.3.6.1.2.1.2.2.1.16.48 | awk {'print $4'}`
old_port6_ou=`cat /tmp/old_port6_ou`
port6_ou=`/usr/bin/expr \( $tmp_port6_ou - $old_port6_ou \) \* 8 / 60 /1000000`
echo $tmp_port6_ou > /tmp/old_port6_ou
參考連結,內有算式 http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a008009496e.shtml
part 2
發現有問題,
octet值是32位元的,超過最大值即歸零,最大值是4294967295 (2的32次方-1)。
shell 需要增加判斷式
if [ `expr $tmp_port6_in - $old_port6_in` -lt "0" ]
then
port6_in=`/usr/bin/expr \( $tmp_port6_in - $old_port6_in + 4294967295 \) \* 8 / 60`
else
port6_in=`/usr/bin/expr \( $tmp_port6_in - $old_port6_in \) \* 8 / 60`
fi
參考連結: http://www.cisco.com/en/US/tech/tk648/tk362/technologies_q_and_a_item09186a00800b69ac.shtml
沒有留言:
張貼留言