1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

refactor: avoid repeating clean_field_name() code

This commit is contained in:
Antoine Beaupré 2012-03-21 15:42:11 -04:00
parent acd97175b6
commit 678f3ed8a9

View file

@ -47,6 +47,14 @@ The relayd.conf configfile (Default: /usr/local/etc/relayd.conf)
=cut =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 $logfile = '/var/log/relayd.log';
my $configfile = "/usr/local/etc/relayd.conf"; my $configfile = "/usr/local/etc/relayd.conf";
@ -77,8 +85,7 @@ if ($cmd eq 'config') {
print("graph_category Load balancer\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"); 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) { for my $host (@hosts) {
my $clean = clean_fieldname($host); my $clean = clean_host($host);
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
print("$clean.label $host\n"); print("$clean.label $host\n");
} }
print("multigraph relayd_incidents\n"); print("multigraph relayd_incidents\n");
@ -88,8 +95,7 @@ if ($cmd eq 'config') {
print("graph_category Load balancer\n"); print("graph_category Load balancer\n");
print("graph_info Number of times this host went down\n"); print("graph_info Number of times this host went down\n");
for my $host (@hosts) { for my $host (@hosts) {
my $clean = clean_fieldname($host); my $clean = clean_host($host);
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
print("$clean.type ABSOLUTE\n"); print("$clean.type ABSOLUTE\n");
print("$clean.label $host\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: $!"); #open(my $log, "tail -100 $logfile |") or die("cannot open $logfile: $!");
while (<$log>) { while (<$log>) {
if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) { if (/host ([^,]*), check[^,]*, state [^>]* -> ([^,]*), availability ([0-9]+.[0-9]+)%/) {
my $host = clean_fieldname($1); my $host = clean_host($1);
$host = clean_fieldname('host'.$1) unless ($host ne '_');
$down{$host} = 0 unless defined $down{$host}; $down{$host} = 0 unless defined $down{$host};
$down{$host}++ if $2 eq 'down'; $down{$host}++ if $2 eq 'down';
@ -146,8 +151,7 @@ save_state($pos);
# get missing availability values from relayctl, if necessary # get missing availability values from relayctl, if necessary
for my $host (@hosts) { for my $host (@hosts) {
my $ran = 0; my $ran = 0;
my $clean = clean_fieldname($host); my $clean = clean_host($host);
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
if (!defined $avail{$clean} && !$ran) { if (!defined $avail{$clean} && !$ran) {
open(my $status, "relayctl show summary|") or die "can't open relayctl: $!"; open(my $status, "relayctl show summary|") or die "can't open relayctl: $!";
while (<$status>) { while (<$status>) {
@ -163,14 +167,12 @@ for my $host (@hosts) {
print "multigraph relayd_avail\n"; print "multigraph relayd_avail\n";
for my $host (@hosts) { for my $host (@hosts) {
my $clean = clean_fieldname($host); my $clean = clean_host($host);
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
print "$clean.value " . ($avail{$clean} || 'NaN'). "\n"; print "$clean.value " . ($avail{$clean} || 'NaN'). "\n";
} }
print "multigraph relayd_incidents\n"; print "multigraph relayd_incidents\n";
for my $host (@hosts) { for my $host (@hosts) {
my $clean = clean_fieldname($host); my $clean = clean_host($host);
$clean = clean_fieldname('host'.$host) unless ($clean ne '_');
print "$clean.value " . ($down{$clean} || 0). "\n"; print "$clean.value " . ($down{$clean} || 0). "\n";
} }