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.7 by pjm2, Mon Jan 22 16:28:57 2001 UTC

# Line 21 | Line 21 | $| = 1;
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  
# Line 45 | Line 64 | sub print_pair($$) {
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 -ak`;
72 +
73 +    # Go through each line of the program, looking for each thing we want.
74 +    my($partition_no) = 0;
75 +    for (my($i) = 0; $i < $#df; $i++) {
76 +        my($line) = $df[$i];
77 +        $line =~ /^(\/[^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/;
78 +        # $4 will not match unless everything before it does...
79 +        if (defined $5) {
80 +            my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5);
81 +            &print_pair("packet.disk.p$partition_no.attributes.name", $filesystem);
82 +            &print_pair("packet.disk.p$partition_no.attributes.kbytes", $kbytes);
83 +            &print_pair("packet.disk.p$partition_no.attributes.used", $used);
84 +            &print_pair("packet.disk.p$partition_no.attributes.avail", $avail);
85 +            &print_pair("packet.disk.p$partition_no.attributes.mount", $mount);
86 +            ++$partition_no;
87 +        }
88 +    }
89 +    
90 + }
91 +
92 + # sub to find out the list of all (non-unique) usernames logged
93 + # in to the machine and how many their are. (not
94   sub include_users() {
95  
96      # Find out all users on this machine.
# Line 59 | Line 105 | sub include_users() {
105   }
106  
107  
108 + # sub to run a series of regexps on the output of 'top' to
109 + # gather various machine statistics.
110   sub include_top() {
111  
112      # Find out some numbers from top.
# Line 84 | Line 132 | sub include_top() {
132      &print_pair("packet.memory.swap_in_use", $top =~ /([^\s]+?)[MG] swap in use/);
133      &print_pair("packet.memory.swap_free", $top =~ /([^\s]+?)[MG] swap free/);
134      
135 + }
136 +
137 + # sub to get details of the machine's operating system.
138 + sub include_osver() {
139 +
140 +    # Find out details about the operating system
141 +    # If these values remain undefined, then the print_pair
142 +    # function shall show the value to be the string "unknown".
143 +    my($os_name) = `uname -s`;
144 +    my($os_release) = `uname -r`;
145 +    my($os_platform) = `uname -m`;
146 +    my($os_sysname) = `uname -n`;
147 +    my($os_version) = `uname -v`;
148 +
149 +    &print_pair("packet.os.name", $os_name);
150 +    &print_pair("packet.os.release", $os_release);
151 +    &print_pair("packet.os.platform", $os_platform);
152 +    &print_pair("packet.os.sysname", $os_sysname);
153 +    &print_pair("packet.os.version", $os_version);
154 +
155   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines