diff options
Diffstat (limited to 'munin-plugin-agesinceseen')
| -rwxr-xr-x | munin-plugin-agesinceseen | 102 | 
1 files changed, 64 insertions, 38 deletions
diff --git a/munin-plugin-agesinceseen b/munin-plugin-agesinceseen index e6fb239..5740df5 100755 --- a/munin-plugin-agesinceseen +++ b/munin-plugin-agesinceseen @@ -1,41 +1,67 @@ -#!/bin/sh +#!/usr/bin/perl  # -# Author: Snorre Jensen +# Graph agesinceseen range counts from SiteSummary +# +# Based on bourne shell module written by Snorre Jensen.  Rewritten to +# perl to be able to use the SiteSummary perl module by Petter +# Reinholdtsen.  # License: GNU General Public License +# +# Magick markers (optional): +#%# family=auto +#%# capabilities=autoconf + +use strict; +use warnings; + +use SiteSummary; + +my %counts; + +my %agegroups = get_age_groups(); +my @order = map { $agegroups{$_}; } sort { $a <=> $b } keys %agegroups; + +if (!$ARGV[0]) { +    for_all_hosts(\&handle_host); + +    for my $label (@order) { +	my $key = $label; +	$key =~ s/[ >]+/_/g; +        print "$key.value ", defined $counts{$label} ? $counts{$label} : 0 , "\n"; +    } +} elsif ($ARGV[0] eq "config") { +    print "graph_title SiteSummary AgeSinceSeen\n"; +    print "graph_order ", join(" ", map { s/ /_/g; $_; } @order), "\n"; +    print "graph_vlabel count\n"; +    print "graph_scale yes\n"; +    print "graph_args --base 1000 -l 0\n"; +    print "graph_height 400\n"; +    print "graph_category SiteSummary\n"; + +    my $first = 1; +    for my $label (@order) { +	my $key = $label; +	$key =~ s/[ >]+/_/g; +        if ($first) { +            print "$key.draw AREA\n"; +	    $first = 0; +        } else { +            print "$key.draw STACK\n"; +        } +	print "$key.label $label\n"; +    } +} 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 handle_host { +    my $hostid = shift; +    my %agegroups = get_age_groups(); +    my $agegroup = get_age_group($hostid); +    $counts{$agegroups{$agegroup}}++; +} -ssfile="/var/lib/sitesummary/www/index.html" -if [ ! -r $ssfile ] ; then -    echo Cannot read $ssfile >&2 -    exit -1 -fi - -array=(\>0\ days \>3\ days \>one\ week \>14\ days \>30\ days \>90\ days) -array2=(3_days one_week 14_days 30_days 90_days) -len=${#array[*]} -len2=${#array2[*]} -i=0 - -if [ "$1" = "config" ]; then -    echo 'graph_title SiteSummary AgeSinceSeen' -    echo 'graph_order 0_days 3_days one_week 14_days 30_days 90_days' -    echo 'graph_vlabel count' -    echo 'graph_scale yes' -    echo 'graph_args --base 1000 -l 0' -    echo 'graph_height 400' -    echo 'graph_category SiteSummary' -    echo '0_days.label 0_days' -    echo '0_days.draw AREA' -    while [ $i -lt $len2 ]; do -	echo "${array2[$i]}.label ${array2[$i]}" -		#echo "${array2[$i]}.stack" | sed 's/\ /-/g' -	echo "${array2[$i]}.draw STACK" -	let i++ -    done -else -    while [ $i -lt $len ]; do -	label=${array[$i]}.value  -	value=`cat $ssfile | grep "${array[$i]}" | awk '{ print $3 }'` -	echo "$label $value" | sed 's/>//g' | sed 's/\ /_/' -	let i++ -    done -fi +exit 0;  | 
