--- projects/cms/source/host/generic/statgrab.pl 2001/01/22 04:09:41 1.4 +++ projects/cms/source/host/generic/statgrab.pl 2001/01/22 16:28:57 1.7 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: tdb $ -# $Id: statgrab.pl,v 1.4 2001/01/22 04:09:41 tdb Exp $ +# $Author: pjm2 $ +# $Id: statgrab.pl,v 1.7 2001/01/22 16:28:57 pjm2 Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -21,24 +21,34 @@ $| = 1; # You'd be silly not to use this ;) use strict; +# Run the following components: - &print_ident(); &include_osver(); &include_users(); &include_top(); +&include_disk(); +# End the program normally. 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.4 $'; + print 'version statgrab.pl $Revision: 1.7 $'; 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". sub print_pair($$) { my($name, $value) = @_; @@ -54,6 +64,33 @@ sub print_pair($$) { } +# sub to find out disk partition information, if it exists. +sub include_disk() { + + # Run the df program. + my(@df) = `df -ak`; + + # Go through each line of the program, looking for each thing we want. + my($partition_no) = 0; + for (my($i) = 0; $i < $#df; $i++) { + my($line) = $df[$i]; + $line =~ /^(\/[^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; + # $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("packet.disk.p$partition_no.attributes.name", $filesystem); + &print_pair("packet.disk.p$partition_no.attributes.kbytes", $kbytes); + &print_pair("packet.disk.p$partition_no.attributes.used", $used); + &print_pair("packet.disk.p$partition_no.attributes.avail", $avail); + &print_pair("packet.disk.p$partition_no.attributes.mount", $mount); + ++$partition_no; + } + } + +} + +# sub to find out the list of all (non-unique) usernames logged +# in to the machine and how many their are. (not sub include_users() { # Find out all users on this machine. @@ -68,6 +105,8 @@ sub include_users() { } +# sub to run a series of regexps on the output of 'top' to +# gather various machine statistics. sub include_top() { # Find out some numbers from top. @@ -95,9 +134,12 @@ sub include_top() { } +# sub to get details of the machine's operating system. sub include_osver() { # Find out details about the operating system + # If these values remain undefined, then the print_pair + # function shall show the value to be the string "unknown". my($os_name) = `uname -s`; my($os_release) = `uname -r`; my($os_platform) = `uname -m`;