--- 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 09:59:09 1.5 @@ -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.5 2001/01/22 09:59:09 pjm2 Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -25,6 +25,7 @@ use strict; &include_osver(); &include_users(); &include_top(); +&include_disk(); exit(0); @@ -34,11 +35,13 @@ 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.4 $'; + print 'version statgrab.pl $Revision: 1.5 $'; 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 +57,36 @@ sub print_pair($$) { } +# sub to find out disk partition information, if it exists. +sub include_disk() { + + # Run the df program. + my(@df) = `df -a`; + + # Only look for these partitions at the moment. + my(@partition_list) = qw{ / /home /var /tmp }; + + # Go through each line of the program, looking for each thing we want. + my($scan_for) = '('.join('|', @partition_list).')'; + my($partition_no) = 0; + for (my($i) = 0; $i < $#df; $i++) { + my($line) = $df[$i]; + $line =~ /^$scan_for\s*\(([^\s]*)\s*\):\s*([0-9]*)\s*blocks\s*([0-9]*)\s*files/; + # $4 will not match unless everything before it does... + if (defined $4) { + my ($partition, $mounted, $blocks, $files) = ($1, $2, $3, $4); + &print_pair("packet.disk.p$partition_no.attributes.name", $partition); + &print_pair("packet.disk.p$partition_no.mounted", $mounted); + &print_pair("packet.disk.p$partition_no.blocks", $blocks); + &print_pair("packet.disk.p$partition_no.name", $files); + ++$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 +101,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 +130,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`;