I am running an Apache Tomcat 6 website and would like a way to somehow log the amount of bandwidth used for each virtual host on the site. Is there such a plugin or logging class that I could use to achieve this? Or how much one go about writing one?
As a workaround, if I could figure out how to log individual requests along with the amount of bytes transferred (not the size the file, but the number of actual bytes sent on the wire), I guess I could write a script to add them up. I'd prefer some other type of module though, since I'm not so concerned about tracking individual pagehits.
You can configure Tomcat to do standard logging (in the "common log format") for each of the virtual hosts. Then you have a plethora of software for analyzing the logs, that's the main reason for having the common log format. Free tools like webalizer can do pretty graphs and breakdowns for you, but that's just the tip of the iceberg of tools available to do useful things with the common log format.
We had a similar requirement, but did not want to store and analyze GB's of transfer logs.
The result was an Valve implementation, that will aggregate data by virtual host and publish as mbeans + output to tomcats standard log:
https://github.com/Viskan/AggregatedAccessLog
Let me know (through github) if you'd like a compiled version to test
br B