--- projects/cms/source/host/generic/statgrab.pl 2001/03/15 10:45:15 1.38 +++ projects/cms/source/host/generic/statgrab.pl 2001/03/19 22:38:20 1.39 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: pjm2 $ -# $Id: statgrab.pl,v 1.38 2001/03/15 10:45:15 pjm2 Exp $ +# $Author: tdb $ +# $Id: statgrab.pl,v 1.39 2001/03/19 22:38:20 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -25,7 +25,8 @@ use strict; my($ostype) = `uname -s`; chop($ostype); # Decide which paths we should use. -my($topbin); my($dfbin); my($usersbin); my($unamebin); my($uptimebin); +my($topbin); my($dfbin); my($usersbin); +my($unamebin); my($uptimebin); my($sysctlbin); if ($ostype eq "SunOS") { # covers: Solaris 8 @@ -50,6 +51,7 @@ elsif ($ostype eq "FreeBSD") { $usersbin = "/usr/bin/users"; $unamebin = "/usr/bin/uname"; $uptimebin = "/usr/bin/uptime"; + $sysctlbin = "/sbin/sysctl"; } else { print "statgrab.pl Error: Unable to identify system type - \"$ostype\".\n"; @@ -76,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.38 $'; + print 'version statgrab.pl $Revision: 1.39 $'; print "\n"; } @@ -212,17 +214,15 @@ sub include_top() { # 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); + # get RAM slightly differently + my($real) = `$sysctlbin -n hw.physmem`; + my($free) = $real - `$sysctlbin -n hw.usermem`; - $top =~ /([^\s]+?)([KMG]) Free/; - my($free) = $1; - $free*=1024 if $2 eq "G"; - $free/=1024 if $2 eq "K"; + # turn bytes to megabytes + $real = ($real / 1024) / 1024; + $free = ($free / 1024) / 1024; + + &print_pair(0, "packet.memory.total", $real); &print_pair(0, "packet.memory.free", $free); $top =~ /Swap: ([^\s]+?)([KMG]) Total/; @@ -236,6 +236,12 @@ sub include_top() { $swap_free*=1024 if $2 eq "G"; $swap_free/=1024 if $2 eq "K"; &print_pair(0, "packet.swap.free", $swap_free); + + my($loads) = `$sysctlbin -n vm.loadavg`; + $loads =~ /\s+([^\s]+?)\s+([^\s]+?)\s+([^\s]+?)\s+/; + &print_pair(0, "packet.load.load1", $1); + &print_pair(0, "packet.load.load5", $2); + &print_pair(0, "packet.load.load15", $3); } elsif ($ostype eq "Linux") { &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); @@ -326,9 +332,11 @@ sub include_uptime() { # grab the uptime my($uptime) = `$uptimebin`; - &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/); - &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/); - &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/); + if($ostype ne "FreeBSD") { + &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/); + &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/); + &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/); + } # work out the days, hours, and minutes