Server Monitoring with Munin

Munin is an excellent open source tool for monitoring and graphing server performance metrics. It can be configured to send out alert emails when something goes wrong with your server, and the graphs make it easy to view trends over time: You could see that your site gets much less traffic on a Sunday, for example, or that the number of database queries performed per day has doubled in the last 2 months.

On a Debian-based system installing Munin is as simple as running the following command, and then going to http://your-server/munin/ in your browser:

sudo aptitude install munin

Munin comes with lots of monitoring plugins by default, including those for MySQL, PostgresSQL, Apache, Tomcat, Squid, and for things such a CPU and memory usage, load average, network traffic, and many more. You can also find lots of user submitted plugins on sites like Munin Exchange.

Munin doesn't have to be used solely for monitoring server performance though. Being so easy to extend Munin is also a great tool for tracking non-server performance related trends over time. In just a few lines of code you could write plugins to track the following stats about your website:

  • Number of User signups
  • Google PageRank
  • Pages in Google's index
  • Number of backlinks
  • Number of twitter mentions
  • Alexa traffic rank

The number of pages in Google's index is actually a plugin I've written. Simple put the following code in your /etc/munin/plugins directory to see it in action:

# Munin Plugin to display the number of pages in the
# google index for all of the given websites
# Ben Dowling -

# Change this to whatever sites you're interested in

if [ "$1" = "autoconf" ]; then
        echo yes 
        exit 0

if [ "$1" = "config" ]; then

        echo 'graph_title Number of Pages in Google Index'
        echo 'graph_args --base 1000 -l 0 '
        echo 'graph_vlabel number of pages'
        echo 'graph_category google'
        echo 'graph_info This graph shows the number of pages in the Google index for a given website.'

        for site in $websites
                echo "${name}.label ${site}"
                echo "${name}.draw LINE2"
                echo "${name}.info The number of pages in the google index."
        exit 0

for site in $websites 
        value=$(wget -q --user-agent=Firefox -O - "${site}" | grep -E "of about <b>[0-9,]+</b>" -o | grep -E "[0-9,]+" -o | sed "s/,//g")
        echo "${name}.value ${value}"

For more details about Munin see their homepage, which also includes detailed documentation on writing your own plugins.

Let me know if you can think of any more Munin plugins that could be interesting, or if you've used any yourself!

A good server will be useful for your site. It is not hard to find a good but cheap dedicated hosting these days.

Posted on 21 Oct 2009
If you enjoyed reading this post you might want to follow @coderholic on twitter or browse though the full blog archive.