diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2010-01-26 14:46:04 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2010-01-26 14:46:04 +0000 |
commit | 359e65ff3ea2dfa5500da27bc67eef841dfff9cc (patch) | |
tree | ea2e136e23db8674e51bf753936a0e77c8db6510 | |
parent | e63982416dd7d7f0a9d412033d574b72622434eb (diff) | |
download | sitesummary-359e65ff3ea2dfa5500da27bc67eef841dfff9cc.tar.gz sitesummary-359e65ff3ea2dfa5500da27bc67eef841dfff9cc.tar.bz2 sitesummary-359e65ff3ea2dfa5500da27bc67eef841dfff9cc.tar.xz |
Rewritten new munin module to use SiteSummary.pm.
-rw-r--r-- | SiteSummary.pm | 28 | ||||
-rw-r--r-- | agesinceseen-summary | 24 | ||||
-rw-r--r-- | debian/changelog | 3 | ||||
-rwxr-xr-x | munin-plugin-agesinceseen | 102 |
4 files changed, 97 insertions, 60 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm index beddd4c..93f2eee 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -9,6 +9,8 @@ our $VERSION = 0.01; our @ISA = qw(Exporter); our @EXPORT = qw( for_all_hosts + get_age_group + get_age_groups get_debian_edu_profile get_debian_edu_ver get_debian_ver @@ -340,6 +342,32 @@ sub for_all_hosts { return $count; } +sub get_age_groups { + return ( + 0 => '>0 days', + 3 => '>3 days', + 7 => '>one week', + 14 => '>14 days', + 30 => '>30 days', + 90 => '>90 days', + 180 => '>180 days', + ); +} +sub get_age_group { + my $hostid = shift; + my %agegroups = get_age_groups(); + my $topdir = get_filepath_current($hostid, "/"); + my $age = (time() - (stat($topdir))[9]) / (60 * 60 * 24); + + my $thisgroup; + for my $group (sort { $a <=> $b; } keys %agegroups) { + if ($age > $group) { + $thisgroup = $group; + } + } + return $thisgroup; +} + 1; ######################################################################## diff --git a/agesinceseen-summary b/agesinceseen-summary index 0347393..ddfd7ff 100644 --- a/agesinceseen-summary +++ b/agesinceseen-summary @@ -6,17 +6,6 @@ use warnings; use SiteSummary; use Getopt::Std; -my %agegroup = - ( - 0 => '>0 days', - 3 => '>3 days', - 7 => '>one week', - 14 => '>14 days', - 30 => '>30 days', - 90 => '>90 days', - 180 => '>180 days', -); - my %agedist; my %opts; @@ -37,15 +26,7 @@ print_summary(); sub handle_host { my $hostid = shift; - my $topdir = get_filepath_current($hostid, "/"); - my $age = (time() - (stat($topdir))[9]) / (60 * 60 * 24); - - my $thisgroup; - for my $group (sort { $a <=> $b; } keys %agegroup) { - if ($age > $group) { - $thisgroup = $group; - } - } + my $thisgroup = get_age_group($hostid); if (defined $thisgroup) { if (exists $agedist{$thisgroup}) { push @{$agedist{$thisgroup}}, $hostid ; @@ -57,8 +38,9 @@ sub handle_host { sub print_summary { printf(" %-20s %5s\n", "age", "count"); + my %agegroups = get_age_groups(); for my $group (sort { $a <=> $b; } keys %agedist) { - printf(" %-20s %5d\n", $agegroup{$group}, scalar @{$agedist{$group}}); + printf(" %-20s %5d\n", $agegroups{$group}, scalar @{$agedist{$group}}); if (exists $opts{l}) { for my $hostid (sort @{$agedist{$group}}) { my $hostname = get_hostname($hostid); diff --git a/debian/changelog b/debian/changelog index 20b1513..480952b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,7 +9,8 @@ sitesummary (0.0.59) UNRELEASED; urgency=low in SiteSummary perl module. * Create Nagios hostclass using the result from get_debian_ver(). * New munin plugin drawing graph based on agesinceseen vaules donated - by Sverre Jensen. + by Sverre Jensen. Rewritten to use the SiteSummary perl module by + Petter Reinholdtsen. -- Petter Reinholdtsen <pere@debian.org> Tue, 26 Jan 2010 08:56:53 +0100 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; |