--- projects/cms/source/host/generic/statgrab.pl 2001/01/29 12:21:18 1.17 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/05 08:33:51 1.24 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: tdb $ -# $Id: statgrab.pl,v 1.17 2001/01/29 12:21:18 tdb Exp $ +# $Author: pjm2 $ +# $Id: statgrab.pl,v 1.24 2001/02/05 08:33:51 pjm2 Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -21,7 +21,7 @@ $| = 1; # You'd be silly not to use this ;) use strict; -# Path's +# Paths my($topbin) = "/usr/local/sbin/top"; my($dfbin) = "/usr/bin/df"; my($usersbin) = "/usr/ucb/users"; @@ -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.17 $'; + print 'version statgrab.pl $Revision: 1.24 $'; print "\n"; } @@ -113,7 +113,7 @@ sub include_users() { chop $users; my($users_count) = 0; $users_count++ while $users =~ /\w+/g; - my($users_list) = $users; + my($users_list) = $users." "; &print_pair(1, "packet.users.count", $users_count); &print_pair(0, "packet.users.list", $users_list); @@ -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,32 @@ sub include_osver() { # sub to get system uptime. sub include_uptime() { - # Need a regexp guru to strip the junk on this line + # grab the uptime my($uptime) = `$uptimebin`; + + # work out the days, hours, and minutes + if ($uptime =~ /hr/) { + # 0 minutes + $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:$2:0/; + } + elsif ($uptime =~ /min/) { + # 0 hours + $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:0:$2/; + } + elsif ($uptime =~ /day/) { + # normal + $uptime =~ s/up ([0-9]+) .*, ([0-9]+):([0-9]+)/$1:$2:$3/; + } + else { + # 0 days + $uptime =~ s/up ([0-9]+):([0-9]+)/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); -} \ No newline at end of file +}