Tag Archives: munin

My first Munin plugin

Munin is a great, really useful project for monitoring all sorts of things on servers over short and long term periods, and can help identify and even warn of undue server loads. It is also appropriately and poetically named for one of Odinn’s crows (so I suppose I should have written this on a Wednesday).

We’ve been running Munin on one of our production servers at work for quite some time, and it gives us a lot of confidence that, to say the least, the server is running in its comfort zone around the clock. Among other bits and pieces, we run OPUS and the PDSystem on this box, two of our home grown projects that are available to the students. For some time now I’ve considered writing a plugin for OPUS to show logged in users, and I finally did this, albeit the counts are not nearly so reliable as I’d like for two reasons, but I’ll probably discuss that in another post. Anyway, I arranged for OPUS to drop a simple text file which simply contains counts of online users with the syntax

student: 10
admin: 2

and so on, for each of the categories of users. Then I needed a plugin to deal with this. I decided to write it simple shell script, since its portable and I’m not much of a perl fan.

#!/bin/sh

#
# Munin plugin for OPUS showing online users
# Copyright Colin Turner
# GPL V2+
#

# Munin plugins, at their simplest, are run either with "config" or
# no parameters (I plan to add auto configuration later).
case $1 in
  config)
  # In config mode, we spout out details of the graphs we will have
  # I want one graph, with lots of stacked values. The first one is
  # an AREA, and the others are stacked above them. I also (-l 0)
  # make sure the graph shows everything down to zero.
	cat <<'EOM'
graph_title OPUS online users
graph_args -l 0
graph_vlabel online users
graph_info The number of online users on OPUS is shown.
student.label student
student.min 0
student.draw AREA
staff.label academic
staff.min 0
staff.draw STACK
company.label hr staff
company.min 0
company.draw STACK
supervisor.label supervisor
supervisor.min 0
supervisor.draw STACK
admin.label admin
admin.min 0
admin.draw STACK
root.label root
root.min 0
root.draw STACK
application.label application
application.min 0
application.draw STACK
EOM
	exit 0;;
esac

# Now the plugin is being run for data. Bail if the file is unavailable
if [ ! -r /var/lib/opus/online_users ] ; then
     echo Cannot read /var/lib/opus/online_users >&2
     exit -1
fi

# Otherwise, a quick sed converts the default format to what Munin needs
cat /var/lib/opus/online_users | sed -e "s/:/.value/"

The plugin has now been running for several days, and you can see its output here. There are problems with it, but that’s more to do with PHP, Debian and user choice, and I’ll comment on that another time. However, already it gives me a useful feel for a lot of user behaviour.

Writing Munin plugins is easy, and Munin does so much of the hard work of turning your creation into something useful.