diff options
Diffstat (limited to 'sitesummary/munin-plugin')
-rwxr-xr-x | sitesummary/munin-plugin | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/sitesummary/munin-plugin b/sitesummary/munin-plugin new file mode 100755 index 0000000..a0899db --- /dev/null +++ b/sitesummary/munin-plugin @@ -0,0 +1,66 @@ +#!/usr/bin/perl +# +# Graph site counts from SiteSummary +# +# Magick markers (optional): +#%# family=auto +#%# capabilities=autoconf + +use strict; +use warnings; + +use SiteSummary; + +my %sitelabels; + +if (!$ARGV[0]) { + for_all_hosts(\&handle_host); + # List values in the opposit order of the configuration order, to + # try to get the same order on the graphs and the values. + for my $sitelabel (sort { $b cmp $a } keys %sitelabels) { + my $key = label2key($sitelabel); + print "$key.value ", $sitelabels{$sitelabel}, "\n"; + } +} elsif ($ARGV[0] eq "config") { + for_all_hosts(\&handle_host); + print "graph_title SiteSummary History\n"; + print "graph_order " . join(" ", sort keys %sitelabels), "\n"; + print "graph_vlabel count\n"; + print "graph_scale yes\n"; + print "graph_height 400\n"; + print "graph_category SiteSummary\n"; + + my $first = 1; + for my $sitelabel (sort keys %sitelabels) { + my $key = label2key($sitelabel); + print "$key.label $sitelabel\n"; + if ($first) { + print "$key.draw AREA\n"; + } else { + print "$key.draw STACK\n"; + } + $first = 0; + } +} elsif ($ARGV[0] eq "autoconf") { + # This module is only available when the sitesummary collector is + # installed too, thus we always answer yes. + print "yes\n"; + exit 0; +} + +sub label2key { + my $label = shift; + $label =~ s/[^a-zA-Z0-9_]+/_/g; + $label =~ s/^_+//; + return $label; +} + +sub handle_host { + my $hostid = shift; + for my $site (get_site($hostid)) { + $site = "SiteMissing" unless defined $site; + $sitelabels{$site}++; + } +} + +exit 0; |