diff --git a/plugins/other/munin_stats_plugins b/plugins/other/munin_stats_plugins new file mode 100755 index 00000000..8d0580e7 --- /dev/null +++ b/plugins/other/munin_stats_plugins @@ -0,0 +1,174 @@ +#!/usr/bin/env perl +use 5.010; +use strict; +use warnings; +use autodie; +use Munin::Plugin; +use File::Temp qw(tempdir tempfile); +use Time::HiRes qw(gettimeofday tv_interval); +use File::Spec::Functions qw(catfile); +use File::Basename qw(basename); + +=head1 NAME + +munin_stats_plugins - Report the time it takes to run all munin plugins + +=head1 SYNOPSIS + +In F, because we invoke plugins +with munin-run, some of which may need root privileges: + + [munin_stats_plugins] + user root + +Put this in cron somewhere: + + # Refresh the statistics + MUNIN_STATS_PLUGINS_RELOAD=1 munin-run munin_stats_plugins + +E.g.: + + 40 4 * * * root MUNIN_STATS_PLUGINS_RELOAD=1 munin-run munin_stats_plugins + +Then run it: + + # Get the statistics + munin-run munin_stats_plugins + +=head1 DESCRIPTION + +Runs all the munin plugins in F and reports the +time it takes to run each one with C and L. Since +running all the plugins again on each munin-update run would lead to +epic recursive failure, you have to reload the statistics database +yourself by reloading it in cron somewhere. + +=head1 AUTHOR + +Evar ArnfjErE Bjarmason + +=head1 LICENSE + +This program is in the public domain. + +=head1 MAGIC MARKERS + + #%# family=manual + +=cut + +my $statedir = $ENV{MUNIN_PLUGSTATE}; +my $statefile = $0; $statefile =~ s[^.*/][]; +my $cache = catfile($statedir, $statefile . '-cache'); +my $cache_tmp = "$cache.tmp"; + +my @plugins = parse_plugin_time($cache); + +# We should reload our data +if (not $ARGV[0] and $ENV{MUNIN_STATS_PLUGINS_RELOAD}) { + $ARGV[0] = 'reload'; +} + +given ($ARGV[0]) { + when ("reload") { + # Plugin names + my @plugs = plugin_names(); + + # Run all the plugins + my $time = plugin_times(@plugs); + + write_plugin_times($cache_tmp, $cache, $time); + } + when ("config") { + print <; + }; +} + +sub parse_plugin_time +{ + my ($file) = @_; + + my $cont = slurp($file); + + my @plugins; + while ($cont =~ /^ (?