You are hereBlogs / Matt's blog / Munin Ping Plugin - Changed to show one ping per graph

Munin Ping Plugin - Changed to show one ping per graph


By Matt - Posted on 05 March 2010

I started with the very nice ping script from the consttype blog, but I didn't like that the graph was so hard to read with multiple ping hosts that had similar latencies, and it would time out with more than three IP addresses, and that it took the best ping rather than the average.   So I have changed it to use a faster ping, report a ping of 1000 when it fails to connect (so you get a spike rather than a gap) and be linkable with ping_ipaddress format.

So for example you can put the contents of this plugin in a file in /usr/local/libexec/munin/ping_

Then link to it from munin

cd /etc/munin/plugins
ln -s /usr/local/libexec/munin/ping_ ping_127.0.0.1
/etc/init.d/munin-node restart

This is released under the GPL, same as Munin.  Enjoy.

#!/usr/bin/perl -w
# usage: Link this script as ping_[ipaddr]

use strict;

my $host = $0;
$host =~ s/.*ping_([\d\.]{8,15})$/$1/;

if (@ARGV && $ARGV[0] eq 'config') {
    print </dev/null);
	my $times = $ping[-1];
	my $val = '';
	# second term is avg
	if ($times =~ m{^rtt min/avg/max/mdev = [\d\.]+\/([\d\.]+)}) {
	    $val = $1;
	}else{
	    $val = 1000;
	}
	print "$name.value $val\n";

}

Hi Matt,

Your plugin is just what I need but I'm not a perl head so I'm coming unstuck pretty quickly... I have written a plugin for Munin with PHP however so I'm familiar with the configuration of this.

The script doesn't work (i.e no output in munin) but when I run it from the shell I get this:

2010/04/14-21:05:01 CONNECT TCP Peer: "127.0.0.1:60094" Local: "127.0.0.1:4949"
Unterminated <> operator at /etc/munin/plugins/ping_www.google.com line 10.
2010/04/14-21:05:02 Plugin "ping_www.wic.co.nz" exited with status 2304. ----

Running it from the shell (not surprisingly) yields the same:

root@bob-laptop:/usr/share/munin/plugins# ./ping_
Unterminated <> operator at ./ping_ line 10.

Any ideas?

Bob
http://www.guru.net.nz/

Bob,It's intended for use with IP addresses, which won't fail when dns resolving is not operational.You can edit the regular expression to something like this if you want to match host names.
$host =~ s/.*ping_(\S+)$/$1/;
Matt 

Very useful information, Thank you it helped heaps.

Matthew
Coppola

Create Live Bookmark

Syndicate content

Recent comments

Latest images