2012-02-18 19:51:33 +01:00
|
|
|
#!/usr/bin/env perl
|
2010-10-18 12:54:59 +02:00
|
|
|
# -*- perl -*-
|
2012-02-18 19:51:33 +01:00
|
|
|
# Plugin to monitor the system uptime
|
2010-10-18 12:54:59 +02:00
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
use strict;
|
2012-02-18 19:51:33 +01:00
|
|
|
use warnings;
|
2010-10-18 12:54:59 +02:00
|
|
|
|
|
|
|
my %IN;
|
|
|
|
|
|
|
|
my $sysctl = defined($ENV{sysctl}) ? $ENV{sysctl} : '/sbin/sysctl';
|
2012-02-18 19:51:33 +01:00
|
|
|
my $ostype = `uname -s`;
|
|
|
|
chomp ($ostype);
|
2010-10-18 12:54:59 +02:00
|
|
|
|
|
|
|
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf')) {
|
2012-02-18 23:33:00 +01:00
|
|
|
if ( -x $sysctl ) {
|
|
|
|
print "yes\n";
|
|
|
|
} else {
|
|
|
|
print "no (sysctl binary not found)\n";
|
|
|
|
};
|
|
|
|
exit;
|
2010-10-18 12:54:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
|
|
|
|
print <<EOT ;
|
|
|
|
graph_title Uptime
|
|
|
|
graph_args --base 1000 -l 0
|
|
|
|
graph_vlabel days
|
|
|
|
graph_category system
|
2012-02-18 19:51:33 +01:00
|
|
|
compile.label Kernel age
|
2010-10-18 12:54:59 +02:00
|
|
|
compile.type GAUGE
|
|
|
|
compile.min 0
|
|
|
|
compile.max 1000
|
|
|
|
compile.draw AREA
|
2012-02-18 19:51:33 +01:00
|
|
|
uptime.label Uptime
|
2010-10-18 12:54:59 +02:00
|
|
|
uptime.type GAUGE
|
|
|
|
uptime.min 0
|
|
|
|
uptime.max 1000
|
|
|
|
uptime.draw AREA
|
|
|
|
EOT
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
use Date::Parse;
|
|
|
|
|
|
|
|
my $kern=`sysctl -n kern.version`;
|
|
|
|
$kern=~ /:\s+(.*\S)\s+\w+\@/;
|
2012-02-18 23:32:01 +01:00
|
|
|
#print "Compile: $1\n";
|
2010-10-18 12:54:59 +02:00
|
|
|
$kern=str2time($1);
|
|
|
|
|
2012-02-18 19:51:33 +01:00
|
|
|
my $boot=`sysctl -n kern.boottime`; # OpenBSD will return seconds from the epoch
|
|
|
|
if ($ostype ne "OpenBSD") {
|
|
|
|
$boot=~ / sec = (\d+)/;
|
2012-02-18 23:32:01 +01:00
|
|
|
#print "Boot: $1\n";
|
2012-02-18 19:51:33 +01:00
|
|
|
$boot=$1;
|
|
|
|
}
|
2010-10-18 12:54:59 +02:00
|
|
|
|
|
|
|
my $now=time;
|
|
|
|
|
|
|
|
print "compile.value ",($now-$kern)/60/60/24,"\n";
|
|
|
|
print "uptime.value ",($now-$boot)/60/60/24,"\n";
|