How do I monitor bandwidth usage of individual virtual sites on Apache? (Ubuntu 14).
On our IIS server, we use the performance monitor, save to csv file and have MRTG parse the data and display it as graphs.
Can I do this with MRTG? I read of an unsupported module for Apache (mod_monitor??) that some had tried to use but really don't want to go with unsupported software.
The short answer is that you probably cannot do it without a little additional work.
The longer answer is that, while MRTG can graph anything in theory, you have to provide it with a way to obtain the data. The throughput of a network interface is already provided via SNMP, but the network traffic per virtual server is a little harder to come by, and you need to convince Apache to hand this data over in a format you can use.
You are clearly already aware of much of this, since under IIS you used the performance monitor to obtain the data from the perfstats. In fact, with IIS, instead of dumping the stats to a file and parsing it, you can use a plugin like mrtg-nsclient to query the perfstats directly via the Nagios nsclient++ agent. However, you are using Apache...
One way to achieve it would be to run each virtual server on a separate TCP port, and then use iptables logging rules to count the bytes passed. The output of
iptables -L
can then be parsed by MRTG to get the counters.If you want to use name virtual hosts, though, only Apache's internals have the relevant data.
I have an MRTG data collection plugin that obtains total traffic counts via the mod_status URL. This allows graphing of the number of active Apache threads, and total traffic. However it is not split by virtual server, so you cannot get the individual statistics. Even with ExtendedStatus on, you only see the activity of the current threads, not counts split by vhost. ExtendedStatus will allow you to see how many threads are active per vhost, but not the total bytes transferred by each vhost.
The output you want appears to exist in
mod_watch
which will output one line of statistics per vhost on the URL/watch-list
. However, this is an older module and may require modification in order for it to compile against Apache 2.4. It is also very hard to come by as the author has apparently tried to bury it. It used to be on github but vanished in 2012.Try here: https://github.com/pld-linux/apache-mod_watch for the source, Try here: http://fossies.org/windows/www/httpd-modules-2.4-win64-VC11.zip/index_o.html for the windows binary for Apache 2.4