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.


In reply to Re: Tracking bandwidth by cees
in thread [untitled node, ID 326674] by Samn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.