Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / system / uptime_bsd @ 6272ca0c

Historique | Voir | Annoter | Télécharger (1,17 ko)

1
#!/usr/bin/env perl
2
# -*- perl -*-
3
# Plugin to monitor the system uptime
4
#
5
#%# family=auto
6
#%# capabilities=autoconf
7

    
8
use strict;
9
use warnings;
10

    
11
my %IN;
12

    
13
my $sysctl = defined($ENV{sysctl}) ? $ENV{sysctl} : '/sbin/sysctl';
14
my $ostype = `uname -s`;
15
chomp ($ostype);
16

    
17
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf')) {
18
	if ( -x $sysctl ) {
19
		print "yes\n";
20
	}else{
21
		print "no (sysctl binary not found)\n";
22
	};
23
	exit;
24
};
25

    
26
if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
27
print <<EOT ;
28
graph_title Uptime
29
graph_args --base 1000 -l 0
30
graph_vlabel days
31
graph_category system
32
compile.label Kernel age
33
compile.type GAUGE
34
compile.min 0
35
compile.max 1000
36
compile.draw AREA
37
uptime.label Uptime
38
uptime.type GAUGE
39
uptime.min 0
40
uptime.max 1000
41
uptime.draw AREA
42
EOT
43
exit;
44
}
45

    
46
use Date::Parse;
47

    
48
my $kern=`sysctl -n kern.version`;
49
$kern=~ /:\s+(.*\S)\s+\w+\@/;
50
print "Compile: $1\n";
51
$kern=str2time($1);
52

    
53
my $boot=`sysctl -n kern.boottime`; # OpenBSD will return seconds from the epoch
54
if ($ostype ne "OpenBSD") {
55
        $boot=~ / sec = (\d+)/;
56
        print "Boot: $1\n";
57
        $boot=$1;
58
}
59

    
60
my $now=time;
61

    
62
print "compile.value ",($now-$kern)/60/60/24,"\n";
63
print "uptime.value ",($now-$boot)/60/60/24,"\n";