From 97fd896837fecf22efc6b5661809942a40d2aa30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:25:35 -0500 Subject: [PATCH 01/30] relayd statistics support for munin --- plugins/relayd | 136 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 plugins/relayd diff --git a/plugins/relayd b/plugins/relayd new file mode 100755 index 00000000..b4770066 --- /dev/null +++ b/plugins/relayd @@ -0,0 +1,136 @@ +#! /usr/bin/perl -w + +use strict; +use Munin::Plugin; + +=head1 NAME + +relayd - Plugin to show statistics about relayd load balancer. + +=head1 CONFIGURATION + +The following environment variables are used by this plugin: + +=over 4 + +=item logfile + +The file where MailScanner logs its action (Default: +/var/log/relayd.log) + +=item logtail + +The location of the logtail command (Default: /usr/sbin/logtail) + +=item offsetfile + +The location of the offset file (Default: +/var/log/munin/plugin-state/munin-relayd.offset) + +=back + +=head1 USAGE + +Requires the logtail command somewhere in path + +=head1 TODO + +Parsing relayd.conf would allow us to do the following: + + * determine the hosts in config (may be necessary!) + * determine if the table is completely down (may be *impossible* if a partial + downtime becomes complete between two runs) + +=head1 MAGIC MARKERS + + #%# family=contrib + #%# capabilities= + +We should have "suggest" once we implement more than availability. We should +also autoconf (check if logtail and the logfile exist, basically). + +See http://munin-monitoring.org/wiki/ConcisePlugins + +=cut + +my $logfile = '/var/log/relayd.log'; +my $logtail = '/usr/sbin/logtail'; +my $offsetfile = "/var/munin/plugin-state/munin-relayd.offset"; +my $configfile = "/usr/local/etc/relayd.conf"; + +(defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'}; +(defined($ENV{'logtail'})) and $logtail = $ENV{'logtail'}; +(defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'}; +(defined($ENV{'configfile'})) and $configfile = $ENV{'offsetfile'}; + +my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; + +if ($cmd eq 'config') { + my @hosts = (); + open(my $conf, "<", $configfile); + my $content = join("", <$conf>); + while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { + my $hosts = $2; + $hosts =~ s/#.*$//mg; + @hosts = split /\s+/, $hosts; + } + print("multigraph relayd_avail\n\n"); + print("graph_title Relayd host availability\n"); + print("graph_args --lower-limit 0\n"); + print("graph_vlabel % availability\n"); + print("graph_category Load balancer\n"); + print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); + for my $host (@hosts) { + my $clean = clean_fieldname($host); + print("$clean.label $host\n"); + } + print("\nmultigraph relayd_incidents\n\n"); + print("graph_title Relayd host incidents\n"); + print("graph_args --lower-limit 0\n"); + print("graph_vlabel down incidents\n"); + print("graph_category Load balancer\n"); + print("graph_info Number of times this host went down during \${graph_period}\n"); + for my $host (@hosts) { + my $clean = clean_fieldname($host); + print("$clean.type ABSOLUTE\n"); + print("$clean.label $host\n"); + } + exit(0); +} + +# sample lines: +# Mar 8 23:05:28 rtr0 relayd[81814]: host 209.44.112.101, check http code (2000ms), state up -> down, availability 97.83% +# Mar 8 23:05:28 rtr0 relayd[81814]: host 209.44.112.96, check http code (2001ms), state up -> down, availability 98.12% +# Mar 8 23:05:31 rtr0 relayd[81813]: table hag: 1 added, 2 deleted, 0 changed, 0 killed +# Mar 8 23:05:31 rtr0 relayd[81814]: host 209.44.112.101, check http code (3ms), state down -> up, availability 97.83% +# Mar 8 23:05:31 rtr0 relayd[81814]: host 209.44.112.96, check http code (3ms), state down -> up, availability 98.12% +# Mar 8 23:05:36 rtr0 relayd[81813]: table hag: 2 added, 1 deleted, 0 changed, 0 killed +# Mar 8 23:21:58 rtr0 relayd[81814]: host 209.44.112.96, check http code (2000ms), state up -> down, availability 98.12% +# Mar 8 23:22:01 rtr0 relayd[81813]: table hag: 0 added, 1 deleted, 0 changed, 0 killed + +my (%avail, %down); + +open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!"); +#open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!"); +while (<$log>) { + if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { + my $host = clean_fieldname($1); + $host = clean_fieldname('host'.$1) unless ($host ne '_'); + + $down{$host} = 0 unless defined $down{$host}; + $down{$host}++ if $2 eq 'down'; + # yes, we overwrite previous value and take only the recent one. be sad. + $avail{$host} = $3; + } +} +close($log) or warn "failed to close pipe: $!"; + +print "multigraph relayd_avail\n\n"; +for my $host (keys %avail) { + print "$host.value " . $avail{$host} . "\n"; +} + +print "\nmultigraph relayd_incidents\n\n"; +for my $host (keys %down) { + print "$host.value " . $down{$host} . "\n"; +} From 99df8a0ed189196d6a4d36a6bb8dc6222222c401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:25:37 -0500 Subject: [PATCH 02/30] use parsed hosts all the time --- plugins/relayd | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/relayd b/plugins/relayd index b4770066..b459ee2a 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -65,15 +65,18 @@ my $configfile = "/usr/local/etc/relayd.conf"; my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; +my @hosts = (); +open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; +my $content = join("", <$conf>); +while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { + my $hosts = $2; + $hosts =~ s/#.*$//mg; # comments + $hosts =~ s/^\s+//mg; # trim spaces before lines + print "table $1: $hosts\n" if defined $ENV{MUNIN_DEBUG}; + push @hosts , split /\s+/, $hosts; +} + if ($cmd eq 'config') { - my @hosts = (); - open(my $conf, "<", $configfile); - my $content = join("", <$conf>); - while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { - my $hosts = $2; - $hosts =~ s/#.*$//mg; - @hosts = split /\s+/, $hosts; - } print("multigraph relayd_avail\n\n"); print("graph_title Relayd host availability\n"); print("graph_args --lower-limit 0\n"); @@ -126,11 +129,11 @@ while (<$log>) { close($log) or warn "failed to close pipe: $!"; print "multigraph relayd_avail\n\n"; -for my $host (keys %avail) { - print "$host.value " . $avail{$host} . "\n"; +for my $host (@hosts) { + print "$host.value " . ($avail{$host} || 'NaN'). "\n"; } print "\nmultigraph relayd_incidents\n\n"; -for my $host (keys %down) { - print "$host.value " . $down{$host} . "\n"; +for my $host (@hosts) { + print "$host.value " . ($down{$host} || 0). "\n"; } From cd70960d1e274838fc66e19d9ddf902be9dff4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:25:38 -0500 Subject: [PATCH 03/30] prefix fieldnames in config too --- plugins/relayd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/relayd b/plugins/relayd index b459ee2a..3a1e2ef9 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -85,6 +85,7 @@ if ($cmd eq 'config') { print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); for my $host (@hosts) { my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); print("$clean.label $host\n"); } print("\nmultigraph relayd_incidents\n\n"); @@ -95,6 +96,7 @@ if ($cmd eq 'config') { print("graph_info Number of times this host went down during \${graph_period}\n"); for my $host (@hosts) { my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); print("$clean.type ABSOLUTE\n"); print("$clean.label $host\n"); } From a3f989a9f2e31badd4d75c19df94e2c92ec05bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:25:39 -0500 Subject: [PATCH 04/30] get missing availability values from relayctl, if necessary --- plugins/relayd | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/relayd b/plugins/relayd index 3a1e2ef9..36318d65 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -130,6 +130,22 @@ while (<$log>) { } close($log) or warn "failed to close pipe: $!"; +# get missing availability values from relayctl, if necessary +for my $host (@hosts) { + my $ran = 0; + if (!defined $avail{$host} && !$ran) { + open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; + while (<$status>) { + if (/([\w\.]+)\s+(\d+\.\d+)%/) { + print "found spare value: $2 for $1\n" if defined $ENV{MUNIN_DEBUG}; + $avail{$1} = $2 unless defined($avail{$1}); + } + } + close $status or die "can't close pipe: $!"; + $ran = 1; + } +} + print "multigraph relayd_avail\n\n"; for my $host (@hosts) { print "$host.value " . ($avail{$host} || 'NaN'). "\n"; From 2fae403dd28df1f1bb25f5f32a9c87513b5bdaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:25:40 -0500 Subject: [PATCH 05/30] update todo --- plugins/relayd | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/relayd b/plugins/relayd index 36318d65..dd7e3359 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -35,19 +35,17 @@ Requires the logtail command somewhere in path =head1 TODO -Parsing relayd.conf would allow us to do the following: - - * determine the hosts in config (may be necessary!) * determine if the table is completely down (may be *impossible* if a partial downtime becomes complete between two runs) + * look again at Munin::Plugin to see if we can simplify things here (duh.) + * need_multigraph() =head1 MAGIC MARKERS #%# family=contrib #%# capabilities= -We should have "suggest" once we implement more than availability. We should -also autoconf (check if logtail and the logfile exist, basically). +We should autoconf (check if logtail and the logfile exist, basically). See http://munin-monitoring.org/wiki/ConcisePlugins From f6f1b07a92ac66a1563e6cf0b95e207688d436f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:57:19 -0500 Subject: [PATCH 06/30] properly escape value output --- plugins/relayd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/relayd b/plugins/relayd index dd7e3359..2adaa5b9 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -146,10 +146,14 @@ for my $host (@hosts) { print "multigraph relayd_avail\n\n"; for my $host (@hosts) { - print "$host.value " . ($avail{$host} || 'NaN'). "\n"; + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print "$clean.value " . ($avail{$host} || 'NaN'). "\n"; } print "\nmultigraph relayd_incidents\n\n"; for my $host (@hosts) { - print "$host.value " . ($down{$host} || 0). "\n"; + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print "$clean.value " . ($down{$host} || 0). "\n"; } From e8da2ee51803f1f1fa68f8ce963b4a69d05f2910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 02:57:20 -0500 Subject: [PATCH 07/30] fix syntax --- plugins/relayd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/relayd b/plugins/relayd index 2adaa5b9..16810bc1 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -75,7 +75,7 @@ while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { } if ($cmd eq 'config') { - print("multigraph relayd_avail\n\n"); + print("multigraph relayd_avail\n"); print("graph_title Relayd host availability\n"); print("graph_args --lower-limit 0\n"); print("graph_vlabel % availability\n"); @@ -86,7 +86,7 @@ if ($cmd eq 'config') { $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); print("$clean.label $host\n"); } - print("\nmultigraph relayd_incidents\n\n"); + print("multigraph relayd_incidents\n"); print("graph_title Relayd host incidents\n"); print("graph_args --lower-limit 0\n"); print("graph_vlabel down incidents\n"); @@ -144,14 +144,14 @@ for my $host (@hosts) { } } -print "multigraph relayd_avail\n\n"; +print "multigraph relayd_avail\n"; for my $host (@hosts) { my $clean = clean_fieldname($host); $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); print "$clean.value " . ($avail{$host} || 'NaN'). "\n"; } -print "\nmultigraph relayd_incidents\n\n"; +print "multigraph relayd_incidents\n"; for my $host (@hosts) { my $clean = clean_fieldname($host); $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); From 9f8061ff989d71b6175d3d8497fcde266cb02b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 03:43:01 -0500 Subject: [PATCH 08/30] reindent with spaces --- plugins/relayd | 110 ++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/plugins/relayd b/plugins/relayd index 16810bc1..3a4f29ee 100755 --- a/plugins/relayd +++ b/plugins/relayd @@ -67,38 +67,38 @@ my @hosts = (); open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; my $content = join("", <$conf>); while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { - my $hosts = $2; - $hosts =~ s/#.*$//mg; # comments - $hosts =~ s/^\s+//mg; # trim spaces before lines - print "table $1: $hosts\n" if defined $ENV{MUNIN_DEBUG}; - push @hosts , split /\s+/, $hosts; + my $hosts = $2; + $hosts =~ s/#.*$//mg; # comments + $hosts =~ s/^\s+//mg; # trim spaces before lines + print "table $1: $hosts\n" if defined $ENV{MUNIN_DEBUG}; + push @hosts , split /\s+/, $hosts; } if ($cmd eq 'config') { - print("multigraph relayd_avail\n"); - print("graph_title Relayd host availability\n"); - print("graph_args --lower-limit 0\n"); - print("graph_vlabel % availability\n"); - print("graph_category Load balancer\n"); - print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); - for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print("$clean.label $host\n"); - } - print("multigraph relayd_incidents\n"); - print("graph_title Relayd host incidents\n"); - print("graph_args --lower-limit 0\n"); - print("graph_vlabel down incidents\n"); - print("graph_category Load balancer\n"); - print("graph_info Number of times this host went down during \${graph_period}\n"); - for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print("$clean.type ABSOLUTE\n"); - print("$clean.label $host\n"); - } - exit(0); + print("multigraph relayd_avail\n"); + print("graph_title Relayd host availability\n"); + print("graph_args --lower-limit 0\n"); + print("graph_vlabel % availability\n"); + print("graph_category Load balancer\n"); + print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); + for my $host (@hosts) { + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print("$clean.label $host\n"); + } + print("multigraph relayd_incidents\n"); + print("graph_title Relayd host incidents\n"); + print("graph_args --lower-limit 0\n"); + print("graph_vlabel down incidents\n"); + print("graph_category Load balancer\n"); + print("graph_info Number of times this host went down during \${graph_period}\n"); + for my $host (@hosts) { + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print("$clean.type ABSOLUTE\n"); + print("$clean.label $host\n"); + } + exit(0); } # sample lines: @@ -116,44 +116,44 @@ my (%avail, %down); open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!"); #open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!"); while (<$log>) { - if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { - my $host = clean_fieldname($1); - $host = clean_fieldname('host'.$1) unless ($host ne '_'); + if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { + my $host = clean_fieldname($1); + $host = clean_fieldname('host'.$1) unless ($host ne '_'); - $down{$host} = 0 unless defined $down{$host}; - $down{$host}++ if $2 eq 'down'; - # yes, we overwrite previous value and take only the recent one. be sad. - $avail{$host} = $3; - } + $down{$host} = 0 unless defined $down{$host}; + $down{$host}++ if $2 eq 'down'; + # yes, we overwrite previous value and take only the recent one. be sad. + $avail{$host} = $3; + } } close($log) or warn "failed to close pipe: $!"; # get missing availability values from relayctl, if necessary for my $host (@hosts) { - my $ran = 0; - if (!defined $avail{$host} && !$ran) { - open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; - while (<$status>) { - if (/([\w\.]+)\s+(\d+\.\d+)%/) { - print "found spare value: $2 for $1\n" if defined $ENV{MUNIN_DEBUG}; - $avail{$1} = $2 unless defined($avail{$1}); - } - } - close $status or die "can't close pipe: $!"; - $ran = 1; - } + my $ran = 0; + if (!defined $avail{$host} && !$ran) { + open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; + while (<$status>) { + if (/([\w\.]+)\s+(\d+\.\d+)%/) { + print "found spare value: $2 for $1\n" if defined $ENV{MUNIN_DEBUG}; + $avail{$1} = $2 unless defined($avail{$1}); + } + } + close $status or die "can't close pipe: $!"; + $ran = 1; + } } print "multigraph relayd_avail\n"; for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print "$clean.value " . ($avail{$host} || 'NaN'). "\n"; + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print "$clean.value " . ($avail{$host} || 'NaN'). "\n"; } print "multigraph relayd_incidents\n"; for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print "$clean.value " . ($down{$host} || 0). "\n"; + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + print "$clean.value " . ($down{$host} || 0). "\n"; } From f3eca64edaed9d042470cd6b9c7f20c13030ee1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:42:38 -0500 Subject: [PATCH 09/30] move our plugin in a subdir, like the others --- plugins/{ => relayd}/relayd | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/{ => relayd}/relayd (100%) diff --git a/plugins/relayd b/plugins/relayd/relayd similarity index 100% rename from plugins/relayd rename to plugins/relayd/relayd From 03b11d92579df8ac48c2510d15e763d1de385507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:46:53 -0500 Subject: [PATCH 10/30] use proper DEBUG variable from module --- plugins/relayd/relayd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 3a4f29ee..d6931178 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -70,7 +70,7 @@ while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { my $hosts = $2; $hosts =~ s/#.*$//mg; # comments $hosts =~ s/^\s+//mg; # trim spaces before lines - print "table $1: $hosts\n" if defined $ENV{MUNIN_DEBUG}; + print "table $1: $hosts\n" if defined $Munin::Plugin::DEBUG; push @hosts , split /\s+/, $hosts; } @@ -135,7 +135,7 @@ for my $host (@hosts) { open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; while (<$status>) { if (/([\w\.]+)\s+(\d+\.\d+)%/) { - print "found spare value: $2 for $1\n" if defined $ENV{MUNIN_DEBUG}; + print "found spare value: $2 for $1\n" if defined $Munin::Plugin::DEBUG; $avail{$1} = $2 unless defined($avail{$1}); } } From dc02d800005b01df94954449bb58b42dc60a2d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:48:05 -0500 Subject: [PATCH 11/30] call need_multigraph() on top as this is what the module says --- plugins/relayd/relayd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index d6931178..72c6c621 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -38,7 +38,6 @@ Requires the logtail command somewhere in path * determine if the table is completely down (may be *impossible* if a partial downtime becomes complete between two runs) * look again at Munin::Plugin to see if we can simplify things here (duh.) - * need_multigraph() =head1 MAGIC MARKERS @@ -56,6 +55,8 @@ my $logtail = '/usr/sbin/logtail'; my $offsetfile = "/var/munin/plugin-state/munin-relayd.offset"; my $configfile = "/usr/local/etc/relayd.conf"; +need_multigraph(); + (defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'}; (defined($ENV{'logtail'})) and $logtail = $ENV{'logtail'}; (defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'}; From 9962245e93d61f59719ecca5fc762ff218d4b8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:51:40 -0500 Subject: [PATCH 12/30] remove dependency on logtail --- plugins/relayd/relayd | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 72c6c621..445cbea6 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -29,36 +29,27 @@ The location of the offset file (Default: =back -=head1 USAGE - -Requires the logtail command somewhere in path - =head1 TODO * determine if the table is completely down (may be *impossible* if a partial downtime becomes complete between two runs) - * look again at Munin::Plugin to see if we can simplify things here (duh.) =head1 MAGIC MARKERS #%# family=contrib #%# capabilities= -We should autoconf (check if logtail and the logfile exist, basically). +We should autoconf (check for config file and logfile). See http://munin-monitoring.org/wiki/ConcisePlugins =cut my $logfile = '/var/log/relayd.log'; -my $logtail = '/usr/sbin/logtail'; -my $offsetfile = "/var/munin/plugin-state/munin-relayd.offset"; my $configfile = "/usr/local/etc/relayd.conf"; need_multigraph(); -(defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'}; -(defined($ENV{'logtail'})) and $logtail = $ENV{'logtail'}; (defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'}; (defined($ENV{'configfile'})) and $configfile = $ENV{'offsetfile'}; @@ -114,7 +105,12 @@ if ($cmd eq 'config') { my (%avail, %down); -open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!"); +my $pos = undef; +($pos) = restore_state(); +$po = 0 unless defined($pos); + +($log,$reset) = tail_open($logfile,$pos); +#open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!"); #open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!"); while (<$log>) { if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { @@ -127,7 +123,8 @@ while (<$log>) { $avail{$host} = $3; } } -close($log) or warn "failed to close pipe: $!"; +$pos = tail_close($log) or warn "failed to close pipe: $!"; +save_state($pos); # get missing availability values from relayctl, if necessary for my $host (@hosts) { From 9791e321782cb2710beaad265cff2e5cdf535d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:58:59 -0500 Subject: [PATCH 13/30] fixup: remove the right stuff --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 445cbea6..100d987c 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -50,7 +50,7 @@ my $configfile = "/usr/local/etc/relayd.conf"; need_multigraph(); -(defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'}; +(defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'}; (defined($ENV{'configfile'})) and $configfile = $ENV{'offsetfile'}; my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; From 1b3a25741b703af5d907de293dea62089acc300f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 18:59:55 -0500 Subject: [PATCH 14/30] fix more syntax errors --- plugins/relayd/relayd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 100d987c..34ffbd6b 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -107,9 +107,9 @@ my (%avail, %down); my $pos = undef; ($pos) = restore_state(); -$po = 0 unless defined($pos); +$pos = 0 unless defined($pos); -($log,$reset) = tail_open($logfile,$pos); +my ($log,$reset) = tail_open($logfile,$pos); #open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!"); #open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!"); while (<$log>) { From 2275fef14118110ca1b57b1b6d58d806c1342b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:09:00 -0500 Subject: [PATCH 15/30] fixup: more parse error --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 34ffbd6b..aeebffaf 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -51,7 +51,7 @@ my $configfile = "/usr/local/etc/relayd.conf"; need_multigraph(); (defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'}; -(defined($ENV{'configfile'})) and $configfile = $ENV{'offsetfile'}; +(defined($ENV{'configfile'})) and $configfile = $ENV{'configfile'}; my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; From 93155c82abf8c84eb96424b218c8f556c25f75c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:09:15 -0500 Subject: [PATCH 16/30] remove warning --- plugins/relayd/relayd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index aeebffaf..64cec1ab 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -60,9 +60,10 @@ open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; my $content = join("", <$conf>); while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { my $hosts = $2; + print "table: $1, " if defined $Munin::Plugin::DEBUG; $hosts =~ s/#.*$//mg; # comments $hosts =~ s/^\s+//mg; # trim spaces before lines - print "table $1: $hosts\n" if defined $Munin::Plugin::DEBUG; + print "hosts: $hosts\n" if defined $Munin::Plugin::DEBUG; push @hosts , split /\s+/, $hosts; } From e5ffe76311319a9c5cdf30a6334d16191402e98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:09:32 -0500 Subject: [PATCH 17/30] stronger regex --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 64cec1ab..e2cbe063 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -58,7 +58,7 @@ my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; my @hosts = (); open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; my $content = join("", <$conf>); -while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) { +while ( $content =~ /table\s*<([^>]+)>\s*{([^}]+)}/g) { my $hosts = $2; print "table: $1, " if defined $Munin::Plugin::DEBUG; $hosts =~ s/#.*$//mg; # comments From 70a119e8e5807345be2859b2fa9cff4651fc1c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:18:39 -0500 Subject: [PATCH 18/30] add autoconf capability --- plugins/relayd/relayd | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index e2cbe063..7b199fb6 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -37,11 +37,7 @@ The location of the offset file (Default: =head1 MAGIC MARKERS #%# family=contrib - #%# capabilities= - -We should autoconf (check for config file and logfile). - -See http://munin-monitoring.org/wiki/ConcisePlugins + #%# capabilities=autoconf =cut @@ -93,6 +89,19 @@ if ($cmd eq 'config') { } exit(0); } +elsif ($cmd eq 'autoconf') { + sub fail($) { + my $msg=shift; + print "no ($msg)\n"; + exit(1); + } + fail("$logfile unreadable)") unless -r $logfile; + fail("$configfile unreadable") unless -r $configfile; + open(my $status, "relayctl show summary|") or fail("cannot run relayctl: $!"); + close($status) or fail("cannot run relayctl: $!"); + print "yes"; + exit(0); +} # sample lines: # Mar 8 23:05:28 rtr0 relayd[81814]: host 209.44.112.101, check http code (2000ms), state up -> down, availability 97.83% From 7fdf0482fa50e2f64549df446e41e9cf5d94f554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:19:48 -0500 Subject: [PATCH 19/30] fix debug printing --- plugins/relayd/relayd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 7b199fb6..6590f801 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -56,10 +56,10 @@ open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; my $content = join("", <$conf>); while ( $content =~ /table\s*<([^>]+)>\s*{([^}]+)}/g) { my $hosts = $2; - print "table: $1, " if defined $Munin::Plugin::DEBUG; + print "table: $1, " if $Munin::Plugin::DEBUG; $hosts =~ s/#.*$//mg; # comments $hosts =~ s/^\s+//mg; # trim spaces before lines - print "hosts: $hosts\n" if defined $Munin::Plugin::DEBUG; + print "hosts: $hosts\n" if $Munin::Plugin::DEBUG; push @hosts , split /\s+/, $hosts; } @@ -143,7 +143,7 @@ for my $host (@hosts) { open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; while (<$status>) { if (/([\w\.]+)\s+(\d+\.\d+)%/) { - print "found spare value: $2 for $1\n" if defined $Munin::Plugin::DEBUG; + print "found spare value: $2 for $1\n" if $Munin::Plugin::DEBUG; $avail{$1} = $2 unless defined($avail{$1}); } } From b1c036702724048603698a4d926795b5d2ec30cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:24:50 -0500 Subject: [PATCH 20/30] distinguish between open and close for pipe error messages --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 6590f801..008d1fa1 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -97,7 +97,7 @@ elsif ($cmd eq 'autoconf') { } fail("$logfile unreadable)") unless -r $logfile; fail("$configfile unreadable") unless -r $configfile; - open(my $status, "relayctl show summary|") or fail("cannot run relayctl: $!"); + open(my $status, "relayctl show summary|") or fail("cannot open relayctl pipe: $!"); close($status) or fail("cannot run relayctl: $!"); print "yes"; exit(0); From 468d26f34f8f4f20a636591cd5d6d1fa170fa12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:25:42 -0500 Subject: [PATCH 21/30] discard config file --- plugins/relayd/relayd | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 008d1fa1..9bdffda1 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -98,6 +98,7 @@ elsif ($cmd eq 'autoconf') { fail("$logfile unreadable)") unless -r $logfile; fail("$configfile unreadable") unless -r $configfile; open(my $status, "relayctl show summary|") or fail("cannot open relayctl pipe: $!"); + () = <$status>; close($status) or fail("cannot run relayctl: $!"); print "yes"; exit(0); From 20191c2b0cc59c2f8b136c81b96cd03510bae93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:25:48 -0500 Subject: [PATCH 22/30] proper yes --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 9bdffda1..45ac5e6d 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -100,7 +100,7 @@ elsif ($cmd eq 'autoconf') { open(my $status, "relayctl show summary|") or fail("cannot open relayctl pipe: $!"); () = <$status>; close($status) or fail("cannot run relayctl: $!"); - print "yes"; + print "yes\n"; exit(0); } From 10f90b04c302d3e3e3840029641125b2ba676008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:27:29 -0500 Subject: [PATCH 23/30] explain why we read data we then discard --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 45ac5e6d..d6174128 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -98,7 +98,7 @@ elsif ($cmd eq 'autoconf') { fail("$logfile unreadable)") unless -r $logfile; fail("$configfile unreadable") unless -r $configfile; open(my $status, "relayctl show summary|") or fail("cannot open relayctl pipe: $!"); - () = <$status>; + () = <$status>; # necessary to avoid SIGPIPE to relayctl, which would make it fail close($status) or fail("cannot run relayctl: $!"); print "yes\n"; exit(0); From e2a069517f713a60c011186ee53598cad956985a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:28:15 -0500 Subject: [PATCH 24/30] document the configuration file --- plugins/relayd/relayd | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index d6174128..77a2e8d2 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -18,14 +18,9 @@ The following environment variables are used by this plugin: The file where MailScanner logs its action (Default: /var/log/relayd.log) -=item logtail +=item configfile -The location of the logtail command (Default: /usr/sbin/logtail) - -=item offsetfile - -The location of the offset file (Default: -/var/log/munin/plugin-state/munin-relayd.offset) +The relayd.conf configfile (Default: /usr/local/etc/relayd.conf) =back From 849e68a858816ae26e7470d71545a339dae3df35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:32:38 -0500 Subject: [PATCH 25/30] explain how to configure logs --- plugins/relayd/relayd | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 77a2e8d2..3be9cf72 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -15,9 +15,20 @@ The following environment variables are used by this plugin: =item logfile -The file where MailScanner logs its action (Default: +The file where syslog logs relayd's action (Default: /var/log/relayd.log) +You need an entry like this in your syslog.conf for this to work: + +!relayd +*.* /var/log/relayd.log + +The directive: + +log updates + +is also necessary in relayd.conf. + =item configfile The relayd.conf configfile (Default: /usr/local/etc/relayd.conf) From 6871dd842df109b86e00faae787cfdb372e44348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 9 Mar 2012 19:35:32 -0500 Subject: [PATCH 26/30] remove non-instanced variable --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 3be9cf72..237855ec 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -86,7 +86,7 @@ if ($cmd eq 'config') { print("graph_args --lower-limit 0\n"); print("graph_vlabel down incidents\n"); print("graph_category Load balancer\n"); - print("graph_info Number of times this host went down during \${graph_period}\n"); + print("graph_info Number of times this host went down\n"); for my $host (@hosts) { my $clean = clean_fieldname($host); $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); From 03302b38aa86a8eca48dfb32ddfbdc5ad8f5eb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 21 Mar 2012 15:31:07 -0400 Subject: [PATCH 27/30] do not set a lower limit for percentages, but a higher limit --- plugins/relayd/relayd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 237855ec..7f6523b7 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -72,7 +72,7 @@ while ( $content =~ /table\s*<([^>]+)>\s*{([^}]+)}/g) { if ($cmd eq 'config') { print("multigraph relayd_avail\n"); print("graph_title Relayd host availability\n"); - print("graph_args --lower-limit 0\n"); + print("graph_args --upper-limit 100\n"); print("graph_vlabel % availability\n"); print("graph_category Load balancer\n"); print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); From acd97175b60ff35146fe1aa59edb416aa33d3433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 21 Mar 2012 15:32:03 -0400 Subject: [PATCH 28/30] fix both display of incidents and usage of existing stats we were not using the right key --- plugins/relayd/relayd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 7f6523b7..68c237ae 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -146,7 +146,9 @@ save_state($pos); # get missing availability values from relayctl, if necessary for my $host (@hosts) { my $ran = 0; - if (!defined $avail{$host} && !$ran) { + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + if (!defined $avail{$clean} && !$ran) { open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; while (<$status>) { if (/([\w\.]+)\s+(\d+\.\d+)%/) { @@ -163,12 +165,12 @@ print "multigraph relayd_avail\n"; for my $host (@hosts) { my $clean = clean_fieldname($host); $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print "$clean.value " . ($avail{$host} || 'NaN'). "\n"; + print "$clean.value " . ($avail{$clean} || 'NaN'). "\n"; } print "multigraph relayd_incidents\n"; for my $host (@hosts) { my $clean = clean_fieldname($host); $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); - print "$clean.value " . ($down{$host} || 0). "\n"; + print "$clean.value " . ($down{$clean} || 0). "\n"; } From 678f3ed8a96afeb9fc7b2282bf1da72b36c4df82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 21 Mar 2012 15:42:11 -0400 Subject: [PATCH 29/30] refactor: avoid repeating clean_field_name() code --- plugins/relayd/relayd | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index 68c237ae..bfe4b66c 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -47,6 +47,14 @@ The relayd.conf configfile (Default: /usr/local/etc/relayd.conf) =cut +# wrapper around clean_fieldname() which is too dumb to parse IPs +sub clean_host($) { + my $host = shift; + my $clean = clean_fieldname($host); + $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + return $clean; +} + my $logfile = '/var/log/relayd.log'; my $configfile = "/usr/local/etc/relayd.conf"; @@ -77,8 +85,7 @@ if ($cmd eq 'config') { print("graph_category Load balancer\n"); print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n"); for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + my $clean = clean_host($host); print("$clean.label $host\n"); } print("multigraph relayd_incidents\n"); @@ -88,8 +95,7 @@ if ($cmd eq 'config') { print("graph_category Load balancer\n"); print("graph_info Number of times this host went down\n"); for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + my $clean = clean_host($host); print("$clean.type ABSOLUTE\n"); print("$clean.label $host\n"); } @@ -131,8 +137,7 @@ my ($log,$reset) = tail_open($logfile,$pos); #open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!"); while (<$log>) { if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { - my $host = clean_fieldname($1); - $host = clean_fieldname('host'.$1) unless ($host ne '_'); + my $host = clean_host($1); $down{$host} = 0 unless defined $down{$host}; $down{$host}++ if $2 eq 'down'; @@ -146,8 +151,7 @@ save_state($pos); # get missing availability values from relayctl, if necessary for my $host (@hosts) { my $ran = 0; - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + my $clean = clean_host($host); if (!defined $avail{$clean} && !$ran) { open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; while (<$status>) { @@ -163,14 +167,12 @@ for my $host (@hosts) { print "multigraph relayd_avail\n"; for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + my $clean = clean_host($host); print "$clean.value " . ($avail{$clean} || 'NaN'). "\n"; } print "multigraph relayd_incidents\n"; for my $host (@hosts) { - my $clean = clean_fieldname($host); - $clean = clean_fieldname('host'.$host) unless ($clean ne '_'); + my $clean = clean_host($host); print "$clean.value " . ($down{$clean} || 0). "\n"; } From 256709738d6a15b80715d91de4b7af55f1e3905e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 21 Mar 2012 15:42:33 -0400 Subject: [PATCH 30/30] fix backup value usage that broke when using clean values --- plugins/relayd/relayd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/relayd/relayd b/plugins/relayd/relayd index bfe4b66c..8f1e1147 100755 --- a/plugins/relayd/relayd +++ b/plugins/relayd/relayd @@ -156,8 +156,9 @@ for my $host (@hosts) { open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; while (<$status>) { if (/([\w\.]+)\s+(\d+\.\d+)%/) { - print "found spare value: $2 for $1\n" if $Munin::Plugin::DEBUG; - $avail{$1} = $2 unless defined($avail{$1}); + my $h = clean_host($1); + print "found spare value: $2 for $h\n" if $Munin::Plugin::DEBUG; + $avail{$h} = $2 unless defined($avail{$h}); } } close $status or die "can't close pipe: $!";