Jacob Peddicord

Check how much web bandwidth your users are using

April 15, 2008 at 02:24 PM | categories: Programming, Planet Ubuntu | View Comments

This is the ckbw script I briefly mentioned earlier. Before going any deeper into the subject, realize that this script assumes some things about your system:

  1. You are using the "combined" Apache2 log format.
  2. Logs are stored as /home/username.logs/domainname.com.access.log and compatible logrotate (.1, .2, etc) equivalents.
In a general sense, ckbw parses through all log files in the above directory and gets a file size total for all items used. Some things, such as unbuffered PHP scripts, will not return a file size and so will not be counted. Be sure that you at least have a month of logs if using logrotate or data can not be reported accurately. Onto the script itself: ckbw script; Perl Basic usage: ckbw apr - grab the bandwidth used in April on the current user sudo -u bob ckbw apr - get the bandwidth used in April by "bob" The script is hardcoded to grab the bandwidth per user and not per site, but it should be very easy to adapt it for a getting stats of a single site. If anyone has a more elegant way of grabbing the output of system() or similar without piping to a file, let me know.
blog comments powered by Disqus
Feed Contact Google+ Twitter LinkedIn GitHub identi.ca OpenID Launchpad