From 6272ca0c22ca468fe395d8ee7d0555cd0b0c0654 Mon Sep 17 00:00:00 2001 From: iangregory Date: Sat, 18 Feb 2012 18:51:33 +0000 Subject: [PATCH] Make the uptime_bsd plugin OpenBSD friendly. --- plugins/system/uptime_bsd | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/system/uptime_bsd b/plugins/system/uptime_bsd index c0f8f20c..840d61bb 100755 --- a/plugins/system/uptime_bsd +++ b/plugins/system/uptime_bsd @@ -1,15 +1,18 @@ -#!/usr/local/bin/perl -w +#!/usr/bin/env perl # -*- perl -*- -# Plugin to monitor number of irqs +# 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 ) { @@ -26,12 +29,12 @@ graph_title Uptime graph_args --base 1000 -l 0 graph_vlabel days graph_category system -compile.label kernel age +compile.label Kernel age compile.type GAUGE compile.min 0 compile.max 1000 compile.draw AREA -uptime.label uptime +uptime.label Uptime uptime.type GAUGE uptime.min 0 uptime.max 1000 @@ -47,10 +50,12 @@ $kern=~ /:\s+(.*\S)\s+\w+\@/; print "Compile: $1\n"; $kern=str2time($1); -my $boot=`sysctl -n kern.boottime`; -$boot=~ / sec = (\d+)/; -print "Boot: $1\n"; -$boot=$1; +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;