File: munin_stats.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (116 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (4)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!@@PERL@@
# -*- perl -*-
#
# Copyright (C) 2006-2009 Rodolphe QuiƩdeville <rodolphe@quiedeville.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Magic markers (used by munin-node-configure and some installation scripts):
#%# family=auto
#%# capabilities=autoconf

use strict;
use warnings;

use Munin::Plugin;

my @logs = qw/update graph html limits/;
my $logdir = ($ENV{'logdir'} || $ENV{'MUNIN_LOGDIR'} || '@@LOGDIR@@');

if ($ENV{'fields'}) {
	@logs = split(/ +/, $ENV{'fields'});
}

sub uses_graph_cron {
    my $log_file = $_[0];
    # quick and dirty backport from master
    # It is implemented properly on master, but this would introduce another dependency.
    if (system("tail -1 '$log_file' 2>/dev/null | grep -q 'graphing is cgi, do nothing\$'") == 0) {
        return 0;
    } else {
        return 1;
    }
}


if ($ARGV[0] and $ARGV[0] eq 'autoconf') {
    my $munin_update_location =
                "$Munin::Common::Defaults::MUNIN_LIBDIR/munin-update";

    if (! -e $munin_update_location) {
        print "no (munin-update was not found at $munin_update_location)\n";
        exit 0;
   }

   if (! -x $munin_update_location) {
        print "no ($munin_update_location was found, but is not executable)\n";
        exit 0;
   }
   else {
        print "yes\n";
        exit 0;
   }
}

if ($ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Munin processing time\n",
          "graph_info This graph shows the run time of the four different processes making up a munin-master run.  Munin-master is run from cron every 5 minutes and we want each of the programmes in munin-master to complete before the next instance starts.  Especially munin-update and munin-graph are time consuming and their run time bears watching. If munin-update uses too long time to run please see the munin-update graph to determine which host is slowing it down.  If munin-graph is running too slow you need to get clever (email the munin-users mailing list) unless you can buy a faster computer with better disks to run munin on.\n",
          "graph_args --base 1000 -l 0\n",
          "graph_scale yes\n",
          "graph_vlabel seconds\n",
          "graph_category munin\n";
    foreach my $log (@logs) {
        print "$log.label munin $log\n";
	print "$log.draw AREASTACK\n";

	next unless $log eq "update" || $log eq "graph";

	print "$log.warning 240\n";
        print "$log.critical 285\n";
    }
    exit 0;
}

my %positions = restore_state();
my %times;

foreach my $log (@logs) {
    my $logfile = "$logdir/munin-$log.log";
    my $time = 'U';

    if (! -r $logfile) {
        print "$log.extinfo Can't open $logfile for reading\n";
        print "$log.value $time\n";
        next;
    }

    if (exists $positions{$log}) {
        my ($LOGFILE, undef) = tail_open($logfile, $positions{$log});
        while (<$LOGFILE>) {
                $time = $1 if (/finished \((\d+\.\d+)\ssec\)$/);
        }
        $positions{$log} = tail_close($LOGFILE);
    }
    else {
        # Do nothing on first run except find the current file end.
        $positions{$log} = (stat $logfile)[7];
    }

    print "$log.value $time\n";
}

save_state(%positions);

# vim: ft=perl : ts=4 : expandtab