--- projects/cms/source/host/generic/statgrab.pl 2001/03/19 23:05:55 1.40 +++ projects/cms/source/host/generic/statgrab.pl 2001/03/20 13:04:22 1.41 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: tdb $ -# $Id: statgrab.pl,v 1.40 2001/03/19 23:05:55 tdb Exp $ +# $Id: statgrab.pl,v 1.41 2001/03/20 13:04:22 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -38,7 +38,7 @@ if ($ostype eq "SunOS") { } elsif ($ostype eq "Linux") { # covers: Debian r2.2 - $topbin = "/usr/bin/top -d1 -n0 -b"; + $topbin = "/usr/bin/top -d1 -n2 -b -p0"; $dfbin = "/bin/df"; $usersbin = "/usr/bin/users"; $unamebin = "/bin/uname"; @@ -78,7 +78,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.40 $'; + print 'version statgrab.pl $Revision: 1.41 $'; print "\n"; } @@ -150,7 +150,7 @@ sub include_top() { # Find out some numbers from top. my(@top) = `$topbin`; my($top) = join(" ", @top); - $top =~ s/\n//g; + $top =~ s/\n/ /g; if($ostype eq "SunOS") { &print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/); @@ -191,7 +191,6 @@ sub include_top() { $swap_free/=1024 if $2 eq "K"; &print_pair(0, "packet.swap.free", $swap_free); - # AJ requested total swap instead of swap_in_use, so here we go! &print_pair(0, "packet.swap.total", $swap_free + $swap_in_use); } elsif ($ostype eq "FreeBSD") { @@ -244,16 +243,27 @@ sub include_top() { &print_pair(0, "packet.load.load15", $3); } elsif ($ostype eq "Linux") { + my ($top) = ""; + foreach my $line (@top) { + $top = $line . $top; + } + $top =~ s/\n/ /g; + &print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/); &print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/); &print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/); &print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/); &print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\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.