ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/generic/statgrab.pl
(Generate patch)

Comparing projects/cms/source/host/generic/statgrab.pl (file contents):
Revision 1.1 by pjm2, Fri Jan 19 19:37:59 2001 UTC vs.
Revision 1.5 by pjm2, Mon Jan 22 09:59:09 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines