--- projects/cms/source/host/generic/statgrab.pl 2001/02/05 19:59:35 1.30 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/13 11:57:48 1.32 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: tdb $ -# $Id: statgrab.pl,v 1.30 2001/02/05 19:59:35 tdb Exp $ +# $Id: statgrab.pl,v 1.32 2001/02/13 11:57:48 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -29,7 +29,7 @@ my($topbin); my($dfbin); my($usersbin); my($unamebin); if ($ostype eq "SunOS") { # covers: Solaris 8 - $topbin = "/usr/local/sbin/top"; + $topbin = "/usr/local/sbin/top -d2 -s1 0"; $dfbin = "/usr/bin/df"; $usersbin = "/usr/ucb/users"; $unamebin = "/usr/bin/uname"; @@ -37,7 +37,7 @@ if ($ostype eq "SunOS") { } elsif ($ostype eq "Linux") { # covers: Debian r2.2 - $topbin = "/usr/bin/top"; + $topbin = "/usr/bin/top -d1 -n0 -b"; $dfbin = "/bin/df"; $usersbin = "/usr/bin/users"; $unamebin = "/bin/uname"; @@ -45,7 +45,7 @@ elsif ($ostype eq "Linux") { } elsif ($ostype eq "FreeBSD") { # covers: FreeBSD 4.2-STABLE - $topbin = "/usr/bin/top"; + $topbin = "/usr/bin/top -d2 -s1 0"; $dfbin = "/bin/df"; $usersbin = "/usr/bin/users"; $unamebin = "/usr/bin/uname"; @@ -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.30 $'; + print 'version statgrab.pl $Revision: 1.32 $'; print "\n"; } @@ -146,46 +146,88 @@ sub include_users() { sub include_top() { # Find out some numbers from top. - my(@top) = `$topbin -d2 -s1 0`; + my(@top) = `$topbin`; my($top) = join(" ", @top); $top =~ s/\n//g; - &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); - &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); - &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); - &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); - &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); - &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]+?)% kernel/); - &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); - &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); - - # The following need to be specified in megabytes. - # If they are preceeded by a G, then multiply by 1024. - - $top =~ /([^\s]+?)([MG]) real/; - my($real) = $1; - $real*=1024 if $2 eq "G"; - &print_pair(0, "packet.memory.total", $real); - - $top =~ /([^\s]+?)([MG]) free/; - my($free) = $1; - $free*=1024 if $2 eq "G"; - &print_pair(0, "packet.memory.free", $free); - - $top =~ /([^\s]+?)([MG]) swap in use/; - my($swap_in_use) = $1; - $swap_in_use*=1024 if $2 eq "G"; - # DO NOT print this one out... save it for in a moment... - - $top =~ /([^\s]+?)([MG]) swap free/; - my($swap_free) = $1; - $swap_free*=1024 if $2 eq "G"; - &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); + if($ostype eq "SunOS") { + &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); + &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); + &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); + &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); + &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); + &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]+?)% kernel/); + &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); + &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); + + # The following need to be specified in megabytes. + # If they are preceeded by a G, then multiply by 1024. + + $top =~ /([^\s]+?)([MG]) real/; + my($real) = $1; + $real*=1024 if $2 eq "G"; + &print_pair(0, "packet.memory.total", $real); + + $top =~ /([^\s]+?)([MG]) free/; + my($free) = $1; + $free*=1024 if $2 eq "G"; + &print_pair(0, "packet.memory.free", $free); + + $top =~ /([^\s]+?)([MG]) swap in use/; + my($swap_in_use) = $1; + $swap_in_use*=1024 if $2 eq "G"; + # DO NOT print this one out... save it for in a moment... + + $top =~ /([^\s]+?)([MG]) swap free/; + my($swap_free) = $1; + $swap_free*=1024 if $2 eq "G"; + &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") { + &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); + &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); + &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); + &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/); + + # The following need to be specified in megabytes. + # If they are preceeded by a G, then multiply by 1024. + + # !! Can't get the total memory !! + #$top =~ /([^\s]+?)([MG]) real/; + #my($real) = $1; + #$real*=1024 if $2 eq "G"; + #&print_pair(0, "packet.memory.total", $real); + &print_pair(0, "packet.memory.total", 0); + + $top =~ /([^\s]+?)([MG]) Free/; + my($free) = $1; + $free*=1024 if $2 eq "G"; + &print_pair(0, "packet.memory.free", $free); + + $top =~ /Swap: ([^\s]+?)([MG]) Total/; + my($swap_total) = $1; + $swap_total*=1024 if $2 eq "G"; + &print_pair(0, "packet.swap.total", $swap_total); + + $top =~ /Swap:.*, ([^\s]+?)([MG]) Free/; + my($swap_free) = $1; + $swap_free*=1024 if $2 eq "G"; + &print_pair(0, "packet.swap.free", $swap_free); + } + else { + # we could have some catchall here + } } # sub to get details of the machine's operating system.