--- projects/cms/source/host/generic/statgrab.pl 2001/02/01 03:14:35 1.19 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/04 23:40:39 1.21 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: tdb $ -# $Id: statgrab.pl,v 1.19 2001/02/01 03:14:35 tdb Exp $ +# $Id: statgrab.pl,v 1.21 2001/02/04 23:40:39 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -50,7 +50,7 @@ exit(0); # the host should check this when reading data # means the host must be checked and updated to work with newer versions. sub print_ident() { - print 'version statgrab.pl $Revision: 1.19 $'; + print 'version statgrab.pl $Revision: 1.21 $'; print "\n"; } @@ -131,7 +131,7 @@ sub include_top() { &print_pair(1, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/); &print_pair(1, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/); - &print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s*/); + &print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s.*/); &print_pair(1, "packet.processes.total", $top =~ /([^\s]+?) processes:/); &print_pair(1, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); &print_pair(1, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); @@ -193,9 +193,35 @@ sub include_osver() { # sub to get system uptime. sub include_uptime() { + # grab the uptime my($uptime) = `$uptimebin`; - $uptime =~ /up ([0-9]+) .*, ([0-9]+:[0-9]+)/; - $uptime = "$1:$2"; + + # work out the days, hours, and minutes + if ($uptime =~ /hr/) { + # 0 minutes + $uptime =~ /up ([0-9]+) .*, ([0-9]+) .*,/; + $uptime = "$1:$2:0"; + } + elsif ($uptime =~ /min/) { + # 0 hours + $uptime =~ /up ([0-9]+) .*, ([0-9]+) .*,/; + $uptime = "$1:0:$2"; + } + elsif ($uptime =~ /day/) { + # normal + $uptime =~ /up ([0-9]+) .*, ([0-9]+):([0-9]+)/; + $uptime = "$1:$2:$3"; + } + else { + # 0 days + $uptime =~ /up ([0-9]+):([0-9]+)/; + $uptime = "0:$1:$2"; + } + + # turn into minutes + + $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/; + $uptime = $3 + ($2 + $1*24)*60; &print_pair(0, "packet.os.uptime", $uptime);