One of the annoyances we find with using Munin is writing plugins. It’s not hard or complicated per se (or any worse than with any of the other monitoring tools). However it often seems confusing and fiddly to our little brains. We’ll admit we aren’t Munin Experts, nor want to be.
The implementation details we do know tend to leak out of our heads over time as, although we use the reports frequently, we typically don’t fiddle with the guts of Munin very often. Which is perhaps a good thing.
Yet from time to time we need to tinker and it is mostly with the plugins.
So we’ve built ourselve a template for Munin plugins.
http://sysmonblog.co.uk/misc/munin_template/munin_template_20080729.tar.gz
md5sum 27268243408c29e2a83bf3c95c506275
Our goals
Quick, simple, easy to write plugins.
Copy, paste, just enough hacking to fetch the values you want to graph, and move on with life.
Data Driven
Ideally it’d be a config file so you wouldn’t need to tinker with actual code. However in the interest of simplicity and not trying to re-write the Munin world we’ve opted for a self-contained Perl script.As such, there is a CONFIG structure at the top of the file where you setup various parameters.
Simplify the Common Case
80% of the value, 20% of the effort/complexity.We are not aiming to handle all situations.
We believe most existing standard plugins are accomodated but some features (like the “suggest” magic marker installation hints) have been left out.We still have a clear, simple story for adding such advanced features and we’ll be covering some (like fully supporting autoconf) in future blog posts. Hint hint: subscribe to the blog!
We are open to feedback and suggestions.
Consolidate together what you need to edit.
Everything you typically need to edit is together at the top of the file. There are only two bits you normally need to be concerned with:
- The CONFIG block, to set titles, labels, graphing arguments etc.
- The show_values() sub, which is responsible for getting the values you are monitoring (cpu, memory, disk etc).
Our experience with many munin plugins is that you need to go through the entire code to be sure that you’ve caught everything and this we find is error prone.
Short, Inline, Documentation Hints
This isn’t the place for comprehensive documentation, which already exists on the Munin website.However a few simple well placed “hints” to remind you what is required, and links to the appropriate documentation aide quick grokking and help with writing plugins quickly and easily.
Using the template
As supplied, it is a fully working plugin that reports on load average. Unlike the munin supplied “load” plugin it reports on 1, 5 and 15 minute load averages and we believe will run on more platforms out of the box.
In any event, it doesn’t rely on the linux only “/proc/loadavg” and we’ve tested it on Mac OS X (BSD) and linux. However, our aim was not to improve or critique the existing “load” plugin. Our aim was to provide a template for writing your own plugins.
We re-implemented the load average plugin just to show what is required. It’s also insightful to compare and contrast. To make it work (on a debian / ubuntu box):
Download, (rename) and save to /etc/munin/plugins
Download:
Unbundle:
tar xvf munin_template_20080729.tar.gz
sudo mv munin_template/template /etc/munin/plugins/load_avg
Ensure the permissions allow the plugin to run
sudo chmod a+x /etc/munin/plugins/load_avg
Restart munin
sudo /etc/init.d/munin-node
Now wait five minutes until your munin master gets around to polling and updating your graphs.To create your own plugin using this as a template:
- Download and un-tar from http://sysmonblog.co.uk/misc/munintemplate/munintemplate_20080729.tar.gz
- The MD5 sum is 27268243408c29e2a83bf3c95c506275
- Edit (and rename) the file ‘template’, adjusting CONFIG and show_values() at the top of the file
- Install it, as per above.
- We’d encourage you to read the POD documentation:
perldoc template
We’ve included an HTML version in the download and we’ve made it available online too.
Learn more …
Some more advanced topics still to be covered
- Improving the autoconf support in the template
- Using AREA & STACK graphing
- Using negative graphs and virtual data sources
- Code re-use and best practice (aka, using a library for the common code)
Why not subscribe to this blog via our feed, or email, if these topics interest you.
Feedback and comments are most welcomed.


Leave a comment