Daniel Watrous on Software Engineering

A Collection of Software Problems and Solutions

Software Engineering

Understanding Munin Plugins

Munin is a monitoring tool which captures and graphs system data, such as CPU utilization, load and I/O. Munin is designed so that all data is collected by plugins. This means that every built in graph is a plugin that was included with the Munin distribution. Each plugin adheres to the interface (not a literal OO inteface), as shown below.

munin-plugin-interface

Munin uses Round Robin Database files (.rrd) to store captured data. The default time configuration in Munin collects data in five minute increments.

Some important details:

  • Plugins can be written in any language, including shell scripts, interpreted languages and even compiled languages like C.
  • Plugin output prints to stdout.
  • When the plugin is called with no arguments or with fetch, the output should be the actual data from the monitor
  • The config function defines the characteristics of the graph that is produced.

config

Each Munin plugin is expected to respond to a config call. The output of config is a list of name/value pairs, one per line, a space separating name and value. Config values are further separated into two subsets of configuration data. One defines global properties of the graph while the other defines the details for each datapoint defined for the graph. A reference describing these items is available here: http://munin.readthedocs.org/en/latest/reference/plugin.html.

Here’s the config output from the load plugin. Several graph properties are defined followed by a definition of the single datapoint, “load”.

ubuntu@munin:~$ sudo munin-run load config
graph_title load_dynamic
graph_title Load average
graph_args --base 1000 -l 0
graph_vlabel load
graph_scale no
graph_category system
graph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run "immediately").
load.info 5 minute load average
load.label load

One graph parameter which is not included on the plugin reference above is graph_data_size. This parameter makes it possible to change the size and structure of the RRD file to capture and retain data at different levels of granularity (default is normal, which captures data at a five minute interval).

autoconf

The autoconf should return “yes” or “no” indicating whether the plugin should be activated by default. This part of the script might check to ensure that a required library or specific service is installed on a system to determine whether it should be enabled.

fetch or no argument

This should return the actual values, either in real-time or as cached since the last fetch. If a plugin is called without any arguments, the plugin should return the same as if fetch were called.

Install plugin

Plugins are typically kept in /usr/share/munin/plugins. A symlink is then created from /etc/munin/plugins pointing to the plugin.

Running plugins

It’s possible to run a plugin manually using munin-run.

ubuntu@munin:~$ sudo munin-run load
load.value 0.01

Example

The Munin wiki contains an example, so for now I’ll link to that rather than create my own simple example.

http://munin-monitoring.org/wiki/HowToWritePlugins

Reference

http://guide.munin-monitoring.org/en/latest/plugin/writing.html

Leave A Comment