root / plugins / relayd / relayd @ f3eca64e
Historique | Voir | Annoter | Télécharger (5,76 ko)
| 1 |
#! /usr/bin/perl -w |
|---|---|
| 2 |
|
| 3 |
use strict; |
| 4 |
use Munin::Plugin; |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
relayd - Plugin to show statistics about relayd load balancer. |
| 9 |
|
| 10 |
=head1 CONFIGURATION |
| 11 |
|
| 12 |
The following environment variables are used by this plugin: |
| 13 |
|
| 14 |
=over 4 |
| 15 |
|
| 16 |
=item logfile |
| 17 |
|
| 18 |
The file where MailScanner logs its action (Default: |
| 19 |
/var/log/relayd.log) |
| 20 |
|
| 21 |
=item logtail |
| 22 |
|
| 23 |
The location of the logtail command (Default: /usr/sbin/logtail) |
| 24 |
|
| 25 |
=item offsetfile |
| 26 |
|
| 27 |
The location of the offset file (Default: |
| 28 |
/var/log/munin/plugin-state/munin-relayd.offset) |
| 29 |
|
| 30 |
=back |
| 31 |
|
| 32 |
=head1 USAGE |
| 33 |
|
| 34 |
Requires the logtail command somewhere in path |
| 35 |
|
| 36 |
=head1 TODO |
| 37 |
|
| 38 |
* determine if the table is completely down (may be *impossible* if a partial |
| 39 |
downtime becomes complete between two runs) |
| 40 |
* look again at Munin::Plugin to see if we can simplify things here (duh.) |
| 41 |
* need_multigraph() |
| 42 |
|
| 43 |
=head1 MAGIC MARKERS |
| 44 |
|
| 45 |
#%# family=contrib |
| 46 |
#%# capabilities= |
| 47 |
|
| 48 |
We should autoconf (check if logtail and the logfile exist, basically). |
| 49 |
|
| 50 |
See http://munin-monitoring.org/wiki/ConcisePlugins |
| 51 |
|
| 52 |
=cut |
| 53 |
|
| 54 |
my $logfile = '/var/log/relayd.log'; |
| 55 |
my $logtail = '/usr/sbin/logtail'; |
| 56 |
my $offsetfile = "/var/munin/plugin-state/munin-relayd.offset"; |
| 57 |
my $configfile = "/usr/local/etc/relayd.conf"; |
| 58 |
|
| 59 |
(defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'};
|
| 60 |
(defined($ENV{'logtail'})) and $logtail = $ENV{'logtail'};
|
| 61 |
(defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'};
|
| 62 |
(defined($ENV{'configfile'})) and $configfile = $ENV{'offsetfile'};
|
| 63 |
|
| 64 |
my $cmd = (defined($ARGV[0])) ? $ARGV[0] : ''; |
| 65 |
|
| 66 |
my @hosts = (); |
| 67 |
open(my $conf, "<", $configfile) or die "can't open $configfile: $!"; |
| 68 |
my $content = join("", <$conf>);
|
| 69 |
while ( $content =~ /table\s*<([^>]*)>\s*{([^}]*)}/g) {
|
| 70 |
my $hosts = $2; |
| 71 |
$hosts =~ s/#.*$//mg; # comments |
| 72 |
$hosts =~ s/^\s+//mg; # trim spaces before lines |
| 73 |
print "table $1: $hosts\n" if defined $ENV{MUNIN_DEBUG};
|
| 74 |
push @hosts , split /\s+/, $hosts; |
| 75 |
} |
| 76 |
|
| 77 |
if ($cmd eq 'config') {
|
| 78 |
print("multigraph relayd_avail\n");
|
| 79 |
print("graph_title Relayd host availability\n");
|
| 80 |
print("graph_args --lower-limit 0\n");
|
| 81 |
print("graph_vlabel % availability\n");
|
| 82 |
print("graph_category Load balancer\n");
|
| 83 |
print("graph_info Ratio of time when this host was up. This is provided by relayd itself (not averaged by this plugin)\n");
|
| 84 |
for my $host (@hosts) {
|
| 85 |
my $clean = clean_fieldname($host); |
| 86 |
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
|
| 87 |
print("$clean.label $host\n");
|
| 88 |
} |
| 89 |
print("multigraph relayd_incidents\n");
|
| 90 |
print("graph_title Relayd host incidents\n");
|
| 91 |
print("graph_args --lower-limit 0\n");
|
| 92 |
print("graph_vlabel down incidents\n");
|
| 93 |
print("graph_category Load balancer\n");
|
| 94 |
print("graph_info Number of times this host went down during \${graph_period}\n");
|
| 95 |
for my $host (@hosts) {
|
| 96 |
my $clean = clean_fieldname($host); |
| 97 |
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
|
| 98 |
print("$clean.type ABSOLUTE\n");
|
| 99 |
print("$clean.label $host\n");
|
| 100 |
} |
| 101 |
exit(0); |
| 102 |
} |
| 103 |
|
| 104 |
# sample lines: |
| 105 |
# Mar 8 23:05:28 rtr0 relayd[81814]: host 209.44.112.101, check http code (2000ms), state up -> down, availability 97.83% |
| 106 |
# Mar 8 23:05:28 rtr0 relayd[81814]: host 209.44.112.96, check http code (2001ms), state up -> down, availability 98.12% |
| 107 |
# Mar 8 23:05:31 rtr0 relayd[81813]: table hag: 1 added, 2 deleted, 0 changed, 0 killed |
| 108 |
# Mar 8 23:05:31 rtr0 relayd[81814]: host 209.44.112.101, check http code (3ms), state down -> up, availability 97.83% |
| 109 |
# Mar 8 23:05:31 rtr0 relayd[81814]: host 209.44.112.96, check http code (3ms), state down -> up, availability 98.12% |
| 110 |
# Mar 8 23:05:36 rtr0 relayd[81813]: table hag: 2 added, 1 deleted, 0 changed, 0 killed |
| 111 |
# Mar 8 23:21:58 rtr0 relayd[81814]: host 209.44.112.96, check http code (2000ms), state up -> down, availability 98.12% |
| 112 |
# Mar 8 23:22:01 rtr0 relayd[81813]: table hag: 0 added, 1 deleted, 0 changed, 0 killed |
| 113 |
|
| 114 |
my (%avail, %down); |
| 115 |
|
| 116 |
open(my $log, "$logtail -f $logfile -o $offsetfile |") or die("cannot open $logfile: $!");
|
| 117 |
#open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!");
|
| 118 |
while (<$log>) {
|
| 119 |
if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) {
|
| 120 |
my $host = clean_fieldname($1); |
| 121 |
$host = clean_fieldname('host'.$1) unless ($host ne '_');
|
| 122 |
|
| 123 |
$down{$host} = 0 unless defined $down{$host};
|
| 124 |
$down{$host}++ if $2 eq 'down';
|
| 125 |
# yes, we overwrite previous value and take only the recent one. be sad. |
| 126 |
$avail{$host} = $3;
|
| 127 |
} |
| 128 |
} |
| 129 |
close($log) or warn "failed to close pipe: $!"; |
| 130 |
|
| 131 |
# get missing availability values from relayctl, if necessary |
| 132 |
for my $host (@hosts) {
|
| 133 |
my $ran = 0; |
| 134 |
if (!defined $avail{$host} && !$ran) {
|
| 135 |
open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; |
| 136 |
while (<$status>) {
|
| 137 |
if (/([\w\.]+)\s+(\d+\.\d+)%/) {
|
| 138 |
print "found spare value: $2 for $1\n" if defined $ENV{MUNIN_DEBUG};
|
| 139 |
$avail{$1} = $2 unless defined($avail{$1});
|
| 140 |
} |
| 141 |
} |
| 142 |
close $status or die "can't close pipe: $!"; |
| 143 |
$ran = 1; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
print "multigraph relayd_avail\n"; |
| 148 |
for my $host (@hosts) {
|
| 149 |
my $clean = clean_fieldname($host); |
| 150 |
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
|
| 151 |
print "$clean.value " . ($avail{$host} || 'NaN'). "\n";
|
| 152 |
} |
| 153 |
|
| 154 |
print "multigraph relayd_incidents\n"; |
| 155 |
for my $host (@hosts) {
|
| 156 |
my $clean = clean_fieldname($host); |
| 157 |
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
|
| 158 |
print "$clean.value " . ($down{$host} || 0). "\n";
|
| 159 |
} |
