Operating System - Linux
1829904 Members
2191 Online
109993 Solutions
New Discussion

Re: Calculating bandwidth

 
SOLVED
Go to solution
Jack C_1
New Member

Calculating bandwidth

Hello all,

I've set up SNMP on linux, which is all fine and dandy. I am trying to write a small app that checks how much bandwidth is going through the interface at any given time. I did it in perl, and it works... but the numbers are wrong!

Basically, I pull ifInOctets from snmp. This is the bytes of data that have come in the interface. But when I take the change in that, over the change in time since the last check, the numbers are not right! Low values seem to be ok, but if I generate A LOT of traffic, then it shoots up to 45 MegaBYTES!!! Obviously impossibly over 100-MBit network.

I also tested it against MRTG. MRTG seems to get the right values. What have I done wrong?

Thanks,

-Jack C
http://www.CREPinc.com
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: Calculating bandwidth

Does snmp always return valid values?

I think to help an snmp guru(not me) might need to see your application source code. Could be a simple division error or something.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jack C_1
New Member

Re: Calculating bandwidth

That's true. I check pretty closly though...

One thing I do know is that SNMP counters reset after a certain number. I acounted for that in the program.

Perhaps my timeer is not accurate enough?

Thanks,

-Jack C
Petr Simik_1
Valued Contributor
Solution

Re: Calculating bandwidth

try this scripts - it's checking Lan interface traffic.
Ragu_3
Trusted Contributor

Re: Calculating bandwidth

Another shot, test it with mrtg-rrdtool.
Take random samples across a fixed time period. Can you show me this perl script?
The sampling is not done right.
Debian GNU/Linux for the Enterprise! Ask HP ...
Jack C_1
New Member

Re: Calculating bandwidth

Yes I will post the script on monday, sorry I don't have it with me right now. Also, I will test the script monday, because unfourtunatly I'm on windows right now.

Thanks guys,

-Jack C
Jack C_1
New Member

Re: Calculating bandwidth

OK. The shell script does not run because I do not have the binary therein. (lanadmin).

My perl script is attatched. Sorry it is not very good, as I am not a real perl person.

Thanks again,
-Jack C
http://www.crepinc.com
Al Licause
Trusted Contributor

Re: Calculating bandwidth

A while back I wrote a similar script for Tru64unix. I pulled both input bytes and
output bytes. I didn't use snmp but the figures are the same.

I have a feeling that if you are only capturing and calculating bandwidth based on outpackets, you are shortchanging the calculation.

Bandwidth of a particular interface is made up of both input and output traffic.

Try including the ifoutOctets as well as see if this brings you any closer the expected result.
Al Licause
Trusted Contributor

Re: Calculating bandwidth

Re-reading your original note, I'm wondering if you are forgetting a conversion factor some place ?

I am from the old school of bits/second for throughput numbers so I use the following:

(((ibytes_previous + obytes_previous)*8) - ((ibytes + obytes)*8))/seconds

Jack C_1
New Member

Re: Calculating bandwidth

Well, my data is not total throughput. If you look at the script, you see that I have a separate area for in/out on each interface (except lo). So only IN bandwidth and OUT bandidth are shown. And yes, it is in Bytes Per Second.

Here is a thought. After comparing it to a known level of bandwidth, it seems that I get one low value, then one high. Perhaps, if my timing was not acurate enough, that could happen. Ideas?

Thanks

-Jack C
http://www.crepinc.com