| 21 |
|
# You'd be silly not to use this ;) |
| 22 |
|
use strict; |
| 23 |
|
|
| 24 |
+ |
# Run the following components: - |
| 25 |
+ |
&print_ident(); |
| 26 |
+ |
&include_osver(); |
| 27 |
|
&include_users(); |
| 28 |
|
&include_top(); |
| 29 |
+ |
&include_disk(); |
| 30 |
|
|
| 31 |
+ |
# End the program normally. |
| 32 |
|
exit(0); |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
+ |
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+ |
|
| 41 |
+ |
# prints out an identifier for this version of statgrab.pl |
| 42 |
+ |
# the host should check this when reading data |
| 43 |
+ |
# means the host must be checked and updated to work with newer versions. |
| 44 |
+ |
sub print_ident() { |
| 45 |
+ |
print 'version statgrab.pl $Revision$'; |
| 46 |
+ |
print "\n"; |
| 47 |
+ |
} |
| 48 |
+ |
|
| 49 |
|
# sub to print pairs of data, separated by a single space character. |
| 50 |
+ |
# If the second argument is undefined, then the pair is still printed, |
| 51 |
+ |
# however, the value shall be displayed as the string "unknown". |
| 52 |
|
sub print_pair($$) { |
| 53 |
|
my($name, $value) = @_; |
| 54 |
|
|
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
+ |
# sub to find out disk partition information, if it exists. |
| 68 |
+ |
sub include_disk() { |
| 69 |
+ |
|
| 70 |
+ |
# Run the df program. |
| 71 |
+ |
my(@df) = `df -a`; |
| 72 |
+ |
|
| 73 |
+ |
# Only look for these partitions at the moment. |
| 74 |
+ |
my(@partition_list) = qw{ / /home /var /tmp }; |
| 75 |
+ |
|
| 76 |
+ |
# Go through each line of the program, looking for each thing we want. |
| 77 |
+ |
my($scan_for) = '('.join('|', @partition_list).')'; |
| 78 |
+ |
my($partition_no) = 0; |
| 79 |
+ |
for (my($i) = 0; $i < $#df; $i++) { |
| 80 |
+ |
my($line) = $df[$i]; |
| 81 |
+ |
$line =~ /^$scan_for\s*\(([^\s]*)\s*\):\s*([0-9]*)\s*blocks\s*([0-9]*)\s*files/; |
| 82 |
+ |
# $4 will not match unless everything before it does... |
| 83 |
+ |
if (defined $4) { |
| 84 |
+ |
my ($partition, $mounted, $blocks, $files) = ($1, $2, $3, $4); |
| 85 |
+ |
&print_pair("packet.disk.p$partition_no.attributes.name", $partition); |
| 86 |
+ |
&print_pair("packet.disk.p$partition_no.mounted", $mounted); |
| 87 |
+ |
&print_pair("packet.disk.p$partition_no.blocks", $blocks); |
| 88 |
+ |
&print_pair("packet.disk.p$partition_no.name", $files); |
| 89 |
+ |
++$partition_no; |
| 90 |
+ |
} |
| 91 |
+ |
} |
| 92 |
+ |
|
| 93 |
+ |
} |
| 94 |
+ |
|
| 95 |
+ |
# sub to find out the list of all (non-unique) usernames logged |
| 96 |
+ |
# in to the machine and how many their are. (not |
| 97 |
|
sub include_users() { |
| 98 |
|
|
| 99 |
|
# Find out all users on this machine. |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
+ |
# sub to run a series of regexps on the output of 'top' to |
| 112 |
+ |
# gather various machine statistics. |
| 113 |
|
sub include_top() { |
| 114 |
|
|
| 115 |
|
# Find out some numbers from top. |
| 135 |
|
&print_pair("packet.memory.swap_in_use", $top =~ /([^\s]+?)[MG] swap in use/); |
| 136 |
|
&print_pair("packet.memory.swap_free", $top =~ /([^\s]+?)[MG] swap free/); |
| 137 |
|
|
| 138 |
+ |
} |
| 139 |
+ |
|
| 140 |
+ |
# sub to get details of the machine's operating system. |
| 141 |
+ |
sub include_osver() { |
| 142 |
+ |
|
| 143 |
+ |
# Find out details about the operating system |
| 144 |
+ |
# If these values remain undefined, then the print_pair |
| 145 |
+ |
# function shall show the value to be the string "unknown". |
| 146 |
+ |
my($os_name) = `uname -s`; |
| 147 |
+ |
my($os_release) = `uname -r`; |
| 148 |
+ |
my($os_platform) = `uname -m`; |
| 149 |
+ |
my($os_sysname) = `uname -n`; |
| 150 |
+ |
my($os_version) = `uname -v`; |
| 151 |
+ |
|
| 152 |
+ |
&print_pair("packet.os.name", $os_name); |
| 153 |
+ |
&print_pair("packet.os.release", $os_release); |
| 154 |
+ |
&print_pair("packet.os.platform", $os_platform); |
| 155 |
+ |
&print_pair("packet.os.sysname", $os_sysname); |
| 156 |
+ |
&print_pair("packet.os.version", $os_version); |
| 157 |
+ |
|
| 158 |
|
} |