--- projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:43:45 1.28 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/05 20:27:59 1.31 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: tdb $ -# $Id: statgrab.pl,v 1.28 2001/02/05 17:43:45 tdb Exp $ +# $Id: statgrab.pl,v 1.31 2001/02/05 20:27:59 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -21,13 +21,43 @@ $| = 1; # You'd be silly not to use this ;) use strict; -# Paths -my($topbin) = "/usr/local/sbin/top"; -my($dfbin) = "/usr/bin/df"; -my($usersbin) = "/usr/ucb/users"; -my($unamebin) = "/usr/bin/uname"; -my($uptimebin) = "/usr/bin/uptime"; +# Have to hope this will work really. +my($ostype) = `uname -s`; chop($ostype); +# Decide which paths we should use. +my($topbin); my($dfbin); my($usersbin); my($unamebin); my($uptimebin); + +if ($ostype eq "SunOS") { + # covers: Solaris 8 + $topbin = "/usr/local/sbin/top -d2 -s1 0"; + $dfbin = "/usr/bin/df"; + $usersbin = "/usr/ucb/users"; + $unamebin = "/usr/bin/uname"; + $uptimebin = "/usr/bin/uptime"; +} +elsif ($ostype eq "Linux") { + # covers: Debian r2.2 + $topbin = "/usr/bin/top -d1 -n0 -b"; + $dfbin = "/bin/df"; + $usersbin = "/usr/bin/users"; + $unamebin = "/bin/uname"; + $uptimebin = "/usr/bin/uptime"; +} +elsif ($ostype eq "FreeBSD") { + # covers: FreeBSD 4.2-STABLE + $topbin = "/usr/bin/top -d2 -s1 0"; + $dfbin = "/bin/df"; + $usersbin = "/usr/bin/users"; + $unamebin = "/usr/bin/uname"; + $uptimebin = "/usr/bin/uptime"; +} +else { + print "statgrab.pl Error: Unable to identify system type - \"$ostype\".\n"; + print "\"uname -s\" does not report one of the following known types;\n"; + print " SunOS, Linux, FreeBSD\n"; + exit(1); +} + # Run the following components: - &print_ident(); &include_osver(); @@ -42,15 +72,11 @@ exit(0); - - - - # prints out an identifier for this version of statgrab.pl # 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.28 $'; + print 'version statgrab.pl $Revision: 1.31 $'; print "\n"; } @@ -120,13 +146,10 @@ 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.load.load1", $top =~ /load averages:\s*([^\s]+?),/); - &print_pair(0, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/); - &print_pair(0, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s/); &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/); @@ -207,6 +230,10 @@ 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]+)/); # work out the days, hours, and minutes