--- projects/cms/source/host/generic/statgrab.pl 2001/01/22 09:59:09 1.5 +++ projects/cms/source/host/generic/statgrab.pl 2001/01/22 16:28:57 1.7 @@ -3,7 +3,7 @@ #----------------------------------------------------------------- # Machine statistics grabber # $Author: pjm2 $ -# $Id: statgrab.pl,v 1.5 2001/01/22 09:59:09 pjm2 Exp $ +# $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,21 +21,28 @@ $| = 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.5 $'; + print 'version statgrab.pl $Revision: 1.7 $'; print "\n"; } @@ -61,24 +68,21 @@ sub print_pair($$) { sub include_disk() { # Run the df program. - my(@df) = `df -a`; + my(@df) = `df -ak`; - # 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/; + $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 $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); + 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; } }