Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Tracking bandwidth

by cees (Curate)
on Feb 05, 2004 at 06:04 UTC ( #326706=note: print w/replies, xml ) Need Help??


in reply to Tracking bandwidth

This is probably best done through apache with a combination of the mod_log_config module and mod_logio module that is available in Apache 2.0.x.

You haven't mentioned how you will identify your clients, but it will probably be done with a REFERER header (easily spoofed by end users) or a cookie or query parameter. Either way, you can use the above modules to generate a custom log to track actual bandwidth used.

Something like the following:

LogFormat "%V %a %s %I %O %{Referer}i %q" trackbandwidth CustomLog /var/log/bandwidth trackbandwidth

You will have to choose what you save in the log file, whether it is the cookie headers, or the query string (this will depend on how you plan to identify your clients). The important entries above are the %I and %O which contain the actual number of bytes sent and received for this request (this includes the headers and the content of the request). I am pretty sure that this will take into consideration a user stopping the request part way through the download as well, but I would suggest you test that before taking my word for it.

Then just write a perl script to parse this log file and generate a full report of the bandwidth used per client.

Replies are listed 'Best First'.
Re: Re: Tracking bandwidth
by bean (Monk) on Feb 05, 2004 at 21:08 UTC
    Stopped requests are a real concern because of the way download accelerators like Go!Zilla, FlashGet, and GetRight often work. The more uncouth ones will request a file multiple times at the same time at different Range offsets and then drop connections once they get an overlap - so make sure the %O in mod_logio really works. What a great Apache module! I wish had been available back in 1999-2000, when I was doing this sort of thing. Actually, I was doing the reverse - trying to regulate a free geocities-type site (and prevent residents from using more than their fair share of bandwidth). I ended up counting each partial request at the full size of the file, primarily punishing the warez and pr0n crowd (who tend to use download accelerators the most), which was fine with me.
Re: Re: Tracking bandwidth
by Samn (Monk) on Feb 05, 2004 at 07:07 UTC
    Thank you very much, this solves everything.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://326706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-08-12 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?