--- projects/cms/source/host/generic/statgrab.pl 2001/02/05 08:27:38 1.23 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:05:22 1.25 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: pjm2 $ -# $Id: statgrab.pl,v 1.23 2001/02/05 08:27:38 pjm2 Exp $ +# $Id: statgrab.pl,v 1.25 2001/02/05 17:05:22 pjm2 Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -50,24 +50,19 @@ 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.23 $'; + print 'version statgrab.pl $Revision: 1.25 $'; print "\n"; } # sub to print pairs of data, separated by a single space character. # If the second argument is undefined, then the pair is still printed, -# however, the value shall be displayed as the string "unknown". -# If $type is non-zero, then "0" is printed instead of "unknown". +# however, the value shall be displayed as the the 'default' value +# if the passed value was undefined. sub print_pair($$$) { - my($type, $name, $value) = @_; + my($default, $name, $value) = @_; if (!defined $value) { - if ($type) { - $value = "0.00"; - } - else { - $value = "unknown"; - } + $value = $default; } # Remove the trailing linefeed if we've not already done so. @@ -92,11 +87,11 @@ sub include_disk() { # $4 will not match unless everything before it does... if (defined $5) { my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); - &print_pair(0, "packet.disk.p$partition_no.attributes.name", $filesystem); - &print_pair(1, "packet.disk.p$partition_no.attributes.kbytes", $kbytes); - &print_pair(1, "packet.disk.p$partition_no.attributes.used", $used); - &print_pair(1, "packet.disk.p$partition_no.attributes.avail", $avail); - &print_pair(0, "packet.disk.p$partition_no.attributes.mount", $mount); + &print_pair("unknown", "packet.disk.p$partition_no.attributes.name", $filesystem); + &print_pair(0, "packet.disk.p$partition_no.attributes.kbytes", $kbytes); + &print_pair(0, "packet.disk.p$partition_no.attributes.used", $used); + &print_pair(0, "packet.disk.p$partition_no.attributes.avail", $avail); + &print_pair("unknown", "packet.disk.p$partition_no.attributes.mount", $mount); ++$partition_no; } } @@ -115,8 +110,8 @@ sub include_users() { $users_count++ while $users =~ /\w+/g; my($users_list) = $users." "; - &print_pair(1, "packet.users.count", $users_count); - &print_pair(0, "packet.users.list", $users_list); + &print_pair(0, "packet.users.count", $users_count); + &print_pair("unknown", "packet.users.list", $users_list); } @@ -129,19 +124,19 @@ sub include_top() { my($top) = join(" ", @top); $top =~ s/\n//g; - &print_pair(1, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/); - &print_pair(1, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/); - &print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s+/); - &print_pair(1, "packet.processes.total", $top =~ /([^\s]+?) processes:/); - &print_pair(1, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); - &print_pair(1, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); - &print_pair(1, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); - &print_pair(1, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); - &print_pair(1, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); - &print_pair(1, "packet.cpu.user", $top =~ /([^\s]+?)% user/); - &print_pair(1, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/); - &print_pair(1, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); - &print_pair(1, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); + &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/); + &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. @@ -149,12 +144,12 @@ sub include_top() { $top =~ /([^\s]+?)([MG]) real/; my($real) = $1; $real*=1024 if $2 eq "G"; - &print_pair(1, "packet.memory.real", $real); + &print_pair(0, "packet.memory.real", $real); $top =~ /([^\s]+?)([MG]) free/; my($free) = $1; $free*=1024 if $2 eq "G"; - &print_pair(1, "packet.memory.free", $free); + &print_pair(0, "packet.memory.free", $free); $top =~ /([^\s]+?)([MG]) swap in use/; my($swap_in_use) = $1; @@ -164,10 +159,10 @@ sub include_top() { $top =~ /([^\s]+?)([MG]) swap free/; my($swap_free) = $1; $swap_free*=1024 if $2 eq "G"; - &print_pair(1, "packet.memory.swap_free", $swap_free); + &print_pair(0, "packet.memory.swap_free", $swap_free); # AJ requested total swap instead of swap_in_use, so here we go! - &print_pair(1, "packet.memory.swap_total", $swap_free + $swap_in_use); + &print_pair(0, "packet.memory.swap_total", $swap_free + $swap_in_use); } # sub to get details of the machine's operating system. @@ -182,11 +177,11 @@ sub include_osver() { my($os_sysname) = `$unamebin -n`; my($os_version) = `$unamebin -v`; - &print_pair(0, "packet.os.name", $os_name); - &print_pair(0, "packet.os.release", $os_release); - &print_pair(0, "packet.os.platform", $os_platform); - &print_pair(0, "packet.os.sysname", $os_sysname); - &print_pair(0, "packet.os.version", $os_version); + &print_pair("unknown", "packet.os.name", $os_name); + &print_pair("unknown", "packet.os.release", $os_release); + &print_pair("unknown", "packet.os.platform", $os_platform); + &print_pair("unknown", "packet.os.sysname", $os_sysname); + &print_pair("unknown", "packet.os.version", $os_version); } @@ -219,6 +214,6 @@ sub include_uptime() { $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/; $uptime = $3 + ($2 + $1*24)*60; - &print_pair(0, "packet.os.uptime", $uptime); + &print_pair("unknown", "packet.os.uptime", $uptime); }