Munin supervisor server on a dynamic IP
Following a previous article on tunneling over dynamic IP links I extended the concept to monitoring my online servers via munin from a single webpage, rather than having to keep a host of bookmarks to munin on each node. This has the added benefit of disabling the graphing code and vhost on the clients. Effectively, this means you don’t need apache to run munin on the nodes, a good thing if your node is a tiny VPS. Finally, you get your rrd’s on the master server for each node, making backups easier.
After doing everything described in the previous article above, you are only missing an automatic way of creating tunnels for each node. The idea here is to get the configuration directly from munin.conf, parse the hosts’ address and port and set up the tunnels accordingly. So:
- Your munin.conf should be like this (/etc/munin/munin.conf in Debian/Ubuntu):
[hostname]
address 127.0.0.1
port 5050
use_node_name yes[hostname2]
address 127.0.0.1
port 5051
use_node_name yesand so on.
- Then, use the following snippet in a cron job to parse munin.conf. It removes comments, grabs the two lines after each hostname in brackets, removes the brackets and passes the whole thing to an awk script just cause I like awk:
server# sudo -H -u munin /bin/bash
server$ cd ~
server$ crontab -e
*/5 * * * * grep -v "#" /etc/munin/munin.conf | grep "^\[" --after-context=2 | tr -d "[]" | awk -f ~/t.awk - This is the awk script. It takes grep’s output and uses awk’s awesome record/field parsing to call the script checktunnel from the previous post:
server$ nano -w ~t.awk
BEGIN { RS="--" }
{
#print "Host:" $1 " Addr:" $3 " Port:" $5;
print "~/checktunnel \"" $1 "\" \""$3"\" \""$5"\"" | "/bin/sh";
close("/bin/sh");
}
The whole thing takes about 5 minutes to set up and from then on setting up a munin node is as easy as executing a single command (Debian/Ubuntu), provided of course you have sshd installed:
client# apt-get install munin
Now, your http://server/munin page will have an entry for each host with all the data you need. If you want to you can remove all the cron jobs for munin ( /etc/cron.d/munin ) from the node, so it doesn’t graph at all.