1

I can set warning / critical thresholds in munin.conf (for a plugin that I've written) like this:

load_per_core.load_per_core.warning 0.2 # Low value to trigger warnings
load_per_core.load_per_core.critical 1

This works as expected, I see email notices and the right stuff on the graphs.

But I want to move these config items into a separate file so that I can more easily manage them across servers with Puppet. However when I move these two lines into a new file plugin-conf.d/zz-load_per_core like this:

[load_per_core]
env.load_per_core.warning 0.3 # Low value to trigger warnings
env.load_per_core.critical 1

...it doesn't work. No emails, nothing on the graphs.

I've guessed at the format of the lines starting env.load_per_core so maybe that's what's wrong?

Eric Clack
  • 111
  • 1
  • 3

1 Answers1

2

tldr; Munin configuration key/value pairs are environment variables that are injected into a specific plugin's execution environment at runtime. They must be accessed from within the plugin's code like any other system environment variable.

Munin Plugin Execution

Each munin plugin is a standalone executable file. At runtime, Munin creates a separate environment for each plugin into which it injects variables that the plugin can reference. There are two groups of environment variables: munin core and plugin specific.

Tip: Use munin-run -d load_per_core to see what environment variables are being injected into your plugin's environment.

How to Define Environment Variables

Plugin specific environment variables are declared per plugin using the syntax:

#/etc/munin/plugin-conf.d/zz-name_of_your_plugin
[name_of_your_plugin]
env.identifier value

Which in your case would be:

#/etc/munin/plugin-conf.d/zz-load_per_core
[load_per_core]
env.load_per_core.warning 0.2 

This creates an environment variable with identifier load_per_core.warning that has a value of 0.2 and injects it into the execution environment of the plugin named load_per_core.

Important: Restart munin-node for your changes to take effect:

sudo service munin-node restart 

Where to Define Environment Variables

Plugin variables are defined in the directory /etc/munin/plagin-conf.d.

Munin creates a default config file at this location called munin-node its not recommended to edit this file because munin can overwrite it.

Instead, create a new file for each plugin. Which in your case could be /etc/munin/plugin-conf.d/zz-load_per_core. There are two things to think about when naming your plugin configuration file:

  1. The name is arbitrary in that it doesn't have to relate to your plugin name, it can be anything, but...
  2. Configuration files in this directory are evaluated in alphabetical order and definitions can overwrite each other. So enforce precedence for your configuration file by prefixing the name with zz to ensure it is evaluated after munin-node.

How to Access Environment Variables

Configuration environment variables can be accessed by your plugin's code like any other environment variable. The syntax for this depends on the language used by your plugin. for instance if your plugin was written in bash you could write:

#!/usr/bin/bash
#this would access and print the load_per_core.warning environment var 
#i.e 0.2    
echo $load_per_core.warning 

or in Python:

#!/usr/bin/env python
import os
print os.environ.get('load_per_core.warning')

or in Perl, using the standard Munin library:

#!/usr/bin/perl
use Munin::Plugin;
print_thresholds('load_per_core');

Josip Rodin
  • 1,695
  • 13
  • 18
  • I am testing a plugin that set reasonable thresholds for dedicated servers but not for a shared server. I had no success overriding the thresholds via the plugin configuration file in /etc/munin/plugin-conf.d. Running 'munin-run -d ' showed that the environment variables were being loaded, but munin ignored them. I found http://guide.munin-monitoring.org/en/latest/tutorial/alert.html#munin-alert-variables which implies thresholds must be defined in munin.conf unless the plugin contains code specifically for processing threshold values. My plugin hard-coded the thresholds. – user3657298 May 12 '21 at 21:45