--- projects/cms/source/host/generic/statgrab.pl 2001/02/13 12:18:07 1.33 +++ projects/cms/source/host/generic/statgrab.pl 2001/03/03 21:26:55 1.36 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: tdb $ -# $Id: statgrab.pl,v 1.33 2001/02/13 12:18:07 tdb Exp $ +# $Id: statgrab.pl,v 1.36 2001/03/03 21:26:55 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -76,7 +76,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.33 $'; + print 'version statgrab.pl $Revision: 1.36 $'; print "\n"; } @@ -109,7 +109,7 @@ sub include_disk() { my($partition_no) = 0; for (my($i) = 0; $i < $#df; $i++) { my($line) = $df[$i]; - $line =~ /^(\/[^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; + $line =~ /^([^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; # $4 will not match unless everything before it does... if (defined $5) { my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); @@ -195,10 +195,15 @@ sub include_top() { &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/); &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); - &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); + + # FreeBSD is a bit different, we need to get user and nice. + my($user) = 0; + if($top =~ /([^\s]+?)% user/) { $user += $1; } + if($top =~ /([^\s]+?)% nice/) { $user += $1; } + &print_pair(0, "packet.cpu.user", $user); # The following need to be specified in megabytes. # If they are preceeded by a G, then multiply by 1024. @@ -322,19 +327,19 @@ sub include_uptime() { if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { # normal - $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; + $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+):([0-9]+)/; $uptime = "$1:$2:$3"; } else { if ($uptime =~ /day/) { if ($uptime =~ /hr/) { # 0 minutes - $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; $uptime = "$1:$2:0"; } elsif ($uptime =~ /min/) { # 0 hours - $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; $uptime = "$1:0:$2"; } else {