Archives Under "Programming" (RSS)
Check how much web bandwidth your users are using
15 April 2008 | Planet Ubuntu, Programming | 6 Responses
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:
- You are using the “combined” Apache2 log format.
- 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.