Apache on Ubuntu – How to Monitor Bandwidth Usage by Virtual Host

apache-2.2bandwidthmonitoringUbuntuvirtualhost


My Environment:

Apache 2.2.9, Ubuntu 8.10


I am trying to find a way to monitor the bandwidth usage on my server broken out by each virtualhost WITHOUT installing something like PLESK, CPanel, or ISPConfig that is capable of modifying my server. I guess I am looking for a READ-ONLY solution. Since I manually administrate my servers I don't like the idea of installing a web accessible third party administration panel.

I am not even interested (necessarily) in getting graphical data out of the system, just so long as I can see bandwidth usage numbers by domain (preferably sub-domain as well) in some useful time increments like week/month/day. In the absence of time increments I will just run it in cron and manually capture the necessary time based increases.

I currently run Cacti as a system monitor but have been unable to find anything that I can add to Cacti that will gather the data I am needing. I did have a look at AWStats, but from what I could tell it only gave whole system bandwith usage by device and not by VHost (please correct if I am mistaken there).

So, is there a package I can install that already does just this?

Can I modify Cacti to show this information?

If no to the above, is there some bash script that I can run that will give me this output that I can later integrate into my own code?

Thanks in advance!

Best Answer

What you are looking for is: mod_logio
http://httpd.apache.org/docs/2.0/mod/mod_logio.html

This will allow the logging of input and output number of bytes received/sent per request. You would then pull it from your logs of a particular vhost. I believe apps like Webalizer will read the log then for you and give you a good usage picture.

Some references:
http://www.debian-administration.org/users/chris/weblog/2 http://onlamp.com/pub/a/onlamp/2007/02/02/apache-debugging-logs.html