File: munin-plugin-agesinceseen

package info (click to toggle)
sitesummary 0.0.68
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 412 kB
  • ctags: 100
  • sloc: perl: 1,620; sh: 724; makefile: 84
file content (72 lines) | stat: -rwxr-xr-x 1,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl
#
# 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;

sub label2key {
    my $label = shift;
    $label =~ s/[^a-zA-Z0-9_]+/_/g;
    $label =~ s/^_+//;
    return $label;
}

if (!$ARGV[0]) {
    for_all_hosts(\&handle_host);

    for my $label (@order) {
        my $key = label2key($label);
        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 { label2key($_); } @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 = label2key($label);
        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}}++;
}

exit 0;