I’ve spent a bit of time at work this year bringing all of our servers onto the puppet configuration management system which, incidentally, I’ve been really impressed with – we now have a consistent hosting platform and a structured way of managing it. I came across munin whilst working with puppet – no idea if they are linked, but the two seem to be used together a lot. Anyhow, installing and configuring stuff like munin is so much easier now, so munin went onto the puppet manifests.
There’s a load of info available using the standard munin plugins, plus I added a few more from around the web. But I still found myself wanting a bit more info about what apache was up to though (you can never have too many graphs!). Specifically, some of the servers host several websites, so the server wide stats that the munin apache plugin collects from mod_status weren’t detailed enough. So I’ve written a couple of munin plugins to report apache stats by virtual host.
I’ll make a couple of disclaimers up front:
The plugins are on github, here: http://github.com/benlumley/munin-plugins
They require that each virtual host has its own logfile, using the apache combined log format – I am using
/var/log/apache2/<site>_access.log
The plugin reports stats using the <site> bit to identify them – you could easily change this, its explained in the comments.
The errors plugin also needs an errors logfile at
/var/log/apache2/<site>_error.log
There’s three plugins:
apache_vh_accesses
Draws a stacked graph of accesses per second per virtual host, similar to the regular munin plugin’s apache accesses.
apache_vh_volume
Draws a stacked graph of bandwidth/network traffic per second per virtual host, similar to the regular munin plugin’s apache volume.
apache_vh_errors
Draws a line graph of the apache error rate per request per virtual host. It calculates the “access rate” using the same code as the access rate plugin, then applies this method to the error log as well to get the number of errors per second. It then divides the errors per second by the accesses per second, aiming to flatten the graph, rather than have it peak and trough with daily traffic cycles. Yet to see how effective this is, but aside from a measure of errors, hoping it will help spot new problems/bugs, I’m expecting one day to see a spikes in an otherwise steady line.
You could alter display of any of the graphs easily – see: http://munin.projects.linpro.no/wiki/HowToWritePlugins – in particular, suspect stacked may not be a popular option.
Let me know if you find any of these useful or have any feedback.
Update: http://www.freshnet.org/wordpress/2007/03/08/monitoring-apaches-virtualhost-with-munin/ documents an alternative way to achieve a similar result, but it relies on an apache module that doesn’t play well with apache 2.2 for me.
4 Responses
Zeeshan
21|Jun|2010 1Thanks for these wonderful plugins. I’ll try to use them on my server to monitor my virtual hosts.
Chris
11|Mar|2011 2Hi there, just wanted to say thanks heaps for these plugins! They are great. I use them all the time. However there seems to be an outstanding bug in the “calculate_rate” function.
When the log file it finds is empty it results in a divide by 0 error in the sub and complains in the munin logs. I have a couple of virtual hosts that get configured but not accessed until the client uploads web pages. It causes lots of errors in the munin logs for these scripts.
I fixed this on my sever with a dirty hack that if the value of $age was 0, return 0 and don’t execute :
return round($num_lines/$ago, 4);
Dunno if there is a more elegent fix for this. But I felt I should let you know.
Thanks again for this plugin. It’s awesome!
ben
09|Jul|2011 3Hi, thanks for the feedback.
I was aware of the issue, just not got round to fixing it!
I will do.
Xenon69
04|Aug|2011 4Hi,
If you want this very nice plugin works for virtualmin vhosts, you have to replace lines :
define(‘LOG_PATH’, “/var/log/apache2/”);
by
define(‘LOG_PATH’, “/var/log/virtualmin/”);
and
exec(sprintf(“find %s -iname *_access.log”, LOG_PATH), $files);
by
exec(sprintf(“find %s -iname *_access_log”, LOG_PATH), $files);
in plugin source files.
it should work…
Fred
Leave a reply
Search
Twitter - @benlumley
Archives
Recent Posts
Blogroll
Tags
Stackoverflow