net-snmp, php and bandwidth usage

liunx

Guest
Hi All,

I'm trying to create a script that can track bandwidth usage using SNMP v1. So far I can poll my Cisco switch using the standard ifInOctets (.1.3.6.1.2.1.2.2.1.10) and ifOutOctets (.1.3.6.1.2.1.2.2.1.16) interface OIDs. I get the counter32 values no problem and save them to a database.

Now I'm trying to figure out how to take those counters and track the amount of bandwidth being used. I've tried using this Cisco document <!-- m --><a class="postlink" href="http://www.cisco.com/warp/public/477/SNMP/calculate_bandwidt">http://www.cisco.com/warp/public/477/SN ... e_bandwidt</a><!-- m --> h_snmp.html (<!-- m --><a class="postlink" href="http://www.cisco.com/warp/public/477/SNMP/calculate_bandwidth_snmp.html">http://www.cisco.com/warp/public/477/SN ... _snmp.html</a><!-- m -->) as a quide but it just doesn't produce correct numbers. I have another tool that montiors the bandwidth but it has issues at times, I know it monitors properly (when it works) so I know my numbers aren't correct. Here is a simple test script that I've been playing around with trying to get this to work.


<?php
$ifInOctet_1 = 3267913068; // Counter collected for ifInOctet
$ifOutOctet_1 = 1503651023; // Counter collected for ifOutOctet

$ifInOctet_2 = 3285278909; // Counter collected for ifInOctet 5 minutes later
$ifOutOctet_2 = 1513595403; // Counter collected for ifOutOctet 5 minutes later

$time_between_polls = 300; // Number of seconds between polls

$ifSpeed = 1000000; // The ifspeed that was polled for the port on the switch

$delta = ($ifInOctet_2 - $ifInOctet_1);

$top_eq = $delta * 8 * 100;
$bottom_eq = $time_between_polls * $ifSpeed;

$ifIn_utilization = $top_eq / $bottom_eq;

var_dump($ifIn_utilization);

// Outputs: float(27.7853456)
?>


If I'm doing it right I should be seeing about 190 kilobytes but I'm not.

Any ideas on what I'm doing wrong or if I'm heading in the wrong direction.
 
Back
Top