[clue] [tech] Calculate total bandwidth usage for an interface using rrdtool

Jim Ockers ockers at ockers.net
Fri Jun 10 13:14:48 MDT 2011


Hi Dave,

Thanks for thinking about this.

David L. Anselmi wrote:
> Jim Ockers wrote:
>   
>> What I was thinking was, since we are allowed 5GB in a month, that I would figure out the total
>> bandwidth used in the last 3 weeks, and if the total bandwidth was 3/4 * 5GB then I would start
>> throttling down the available bandwidth on the interface using tc and traffic shaping.
>>     
>
>   
>> I'd like a 3 week time interval, and I want it to interpolate and use zero for NaNs, and give me
>> the AVERAGE BANDWIDTH USAGE FOR THE LAST 3 WEEKS IN ONE NUMBER.
>>     
>
> So you don't really want average bandwidth.  You want bytes transferred.  (You want a value, not a 
> rate, and a total, not an average.)
>   
That's correct, I need a total, but that SHOULD be fairly easy to get by 
taking ( elapsed time ) * (average data rate xferred during that elapsed 
time) .
> What numbers are you getting from the interface?  If you're just using tx/rx_bytes what does rrdtool 
> get you (since tx/rx_bytes is what you want)?
>   
Sure, those would be dandy, I want the tx/rx bytes, so I can subtract 
the start value from the end value for a 3 week interval. Unfortunately 
this system gets rebooted a lot and could be powered off for extended 
periods of time, and so we need something to keep continuous statistics 
for whenever the thing is running, to preserve the state, if you will. 
rrdtool is perfect for saving the state so that it persists over time 
and across reboots, because it stores the rate and not the actual bytes 
tx/rx.
> Seems to me that tx/rx_bytes have these problems:
>
> They roll over eventually.  On a 32 bit system that might be before 5GB.
>   
These things get rebooted often enough that the counters won't roll 
over. But yeah I think the counter rollover is 4GB on an interface for 
32-bit Linux.
> They can't be zeroed unless you reload the driver module (maybe things are different now but I 
> didn't quickly find another way to reset them).
>
> If you reset the counters at the beginning of the month you'll need a way to detect premature 
> resets.  Maybe rrdtool can help with that.
>   
Yes, that's exactly what rrdtool is best for.
> rrdtool seems intent on thinking about your raw numbers in intervals and I don't think that's the 
> problem you have.  But maybe there's an example of people using it to notice thresholds being 
> crossed (running out of disk space or memory).
>
> If you're just looking at the kernel counters, does SNMP offer a way to get the data differently?
>   
Using SNMP would mean preserving the state somewhere else. I need to 
preserve the state on this system itself so that it can keep track of 
the bandwidth usage of its own 3G card, and throttle itself back if it 
starts to approach the limit, to keep the usage under 5GB in any given 
month.

Thanks,
Jim

-- 
Jim Ockers, P.Eng. (ockers at ockers.net)
Contact info: http://www.ockers.net/msi.html


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20110610/e0876cc4/attachment.html 


More information about the clue mailing list