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 work by reading a chunk from the end of the apache logfiles, in fact, they may do this several times, trying to get find a point in the logfile close to 5 minutes ago in time. They seem pretty fast/snappy to me, but if that idea is crazy/scarey to you … well .. make them work some other way and send them back please!
  • The code’s not the cleanest in the world – but it works, I got bored at that point. And yes, all 3 plugins are copy/pastes of each other with minor alterations.
  • Yes, its php.

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.