1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00
Munin-Contrib/plugins/bsd/uptime_bsd
Tomohiro Hosaka bb4d6c64f4 fix uptime_bsd. compile time is not included since FreeBSD 12.0-RELEASE due to Reproducible Builds
https://wiki.freebsd.org/ReproducibleBuilds/Base
https://reviews.freebsd.org/D4347

sysctl output samples:

% (11.2-RELEASE) sysctl kern.version
kern.version: FreeBSD 11.2-RELEASE-p10 #0: Mon May 13 21:20:50 UTC 2019
    root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC

% (12.0-RELEASE) sysctl kern.version
kern.version: FreeBSD 12.0-RELEASE-p7 GENERIC
2019-07-16 00:16:01 +02:00

63 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/env perl
# -*- perl -*-
# Plugin to monitor the system uptime
#
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
my %IN;
my $sysctl = defined($ENV{sysctl}) ? $ENV{sysctl} : '/sbin/sysctl';
my $ostype = `uname -s`;
chomp ($ostype);
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf')) {
if ( -x $sysctl ) {
print "yes\n";
} else {
print "no (sysctl binary not found)\n";
};
exit;
};
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
compile.label Kernel age
compile.type GAUGE
compile.min 0
compile.max 1000
compile.draw AREA
uptime.label Uptime
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+\@/;
#print "Compile: $1\n";
$kern= $1 ? str2time($1) : undef;
my $boot=`sysctl -n kern.boottime`; # OpenBSD will return seconds from the epoch
if ($ostype ne "OpenBSD") {
$boot=~ / sec = (\d+)/;
#print "Boot: $1\n";
$boot=$1;
}
my $now=time;
print "compile.value ",($now-$kern)/60/60/24,"\n" if $kern;
print "uptime.value ",($now-$boot)/60/60/24,"\n";