[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: limiting monthly network traffic



Hi Cameron,

On Fri, May 25, 2007 at 09:10:38PM -0700, cls@truffula.sj.ca.us wrote:
> The new bandwidth allocation is about 8x what I've been using.
> But if I get slashdotted and have a 10x month, it will
> cost too much.
> What's the Debian way to monitor total network traffic
> and throttle down if I get too near the monthly limit?

I'm not aware of a tool that can do this, but it isn't too hard to
script it based on your requirements.

For example, /proc/net/dev contains byte counts of traffic going in
and out on every interface, so you could sample that every 5 minutes
and store the results in an RRD file.  One advantage of the RRD
format is that it automatically gives you a circular buffer so you
don't need to worry about calculating all that.

One way to tell if you need to throttle your bandwidth would then be
to calculate the average transfer rate over the last month.  For
exmaple, if your limit is 100GB (100 * 10^9 bytes) per month then
that is equivalent to an average of 304.2 kilobit/sec.  If your
average for the last month is higher than 304kbit/s then you
could use tc to throttle your outbound data rate to 300kbit/s.
If you checked every 5 minutes then it would not be possible to
exceed 100GB/month by more than the amount transferred in 5 minutes.

If a later reading showed the average had dropped below 304kbit/s
then you could remove the traffic shaping thus allowing bursts of
higher than 304kbit/s again.

There are more thorough and more complicated ways to do this; the
above is just a simple method.  Also the way you want to do it
probably depends on how your provider is measuring you.  For example
if they are measuring you on a 95th percentile basis then you should
probably measure that way too.  That's still easy with an RRD.

Also do bear in mind a couple of other things:

- It's not easy to throttle incoming data.

- When you throttle outgoing data you will see packet loss and the
  drop in service quality will likely be noticeable.

Cheers,
Andy

-- 
http://bitfolk.com/ -- No-nonsense VPS hosting
Encrypted mail welcome - keyid 0x604DE5DB

Attachment: signature.asc
Description: Digital signature


Reply to: