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.27 by tdb, Mon Feb 5 17:21:04 2001 UTC vs.
Revision 1.33 by tdb, Tue Feb 13 12:18:07 2001 UTC

# Line 21 | Line 21 | $| = 1;
21   # You'd be silly not to use this ;)
22   use strict;
23  
24 < # Paths
25 < my($topbin) = "/usr/local/sbin/top";
26 < my($dfbin) = "/usr/bin/df";
27 < my($usersbin) = "/usr/ucb/users";
28 < my($unamebin) = "/usr/bin/uname";
29 < my($uptimebin) = "/usr/bin/uptime";
24 > # Have to hope this will work really.
25 > my($ostype) = `uname -s`; chop($ostype);
26  
27 + # Decide which paths we should use.
28 + my($topbin); my($dfbin); my($usersbin); my($unamebin); my($uptimebin);
29 +
30 + if ($ostype eq "SunOS") {
31 +    # covers: Solaris 8
32 +    $topbin = "/usr/local/sbin/top -d2 -s1 0";
33 +    $dfbin = "/usr/bin/df";
34 +    $usersbin = "/usr/ucb/users";
35 +    $unamebin = "/usr/bin/uname";
36 +    $uptimebin = "/usr/bin/uptime";
37 + }
38 + elsif ($ostype eq "Linux") {
39 +    # covers: Debian r2.2
40 +    $topbin = "/usr/bin/top -d1 -n0 -b";
41 +    $dfbin = "/bin/df";
42 +    $usersbin = "/usr/bin/users";
43 +    $unamebin = "/bin/uname";
44 +    $uptimebin = "/usr/bin/uptime";
45 + }
46 + elsif ($ostype eq "FreeBSD") {
47 +    # covers: FreeBSD 4.2-STABLE
48 +    $topbin = "/usr/bin/top -d2 -s1 0";
49 +    $dfbin = "/bin/df";
50 +    $usersbin = "/usr/bin/users";
51 +    $unamebin = "/usr/bin/uname";
52 +    $uptimebin = "/usr/bin/uptime";
53 + }
54 + else {
55 +    print "statgrab.pl Error: Unable to identify system type - \"$ostype\".\n";
56 +    print "\"uname -s\" does not report one of the following known types;\n";
57 +    print "      SunOS, Linux, FreeBSD\n";
58 +    exit(1);
59 + }
60 +
61   # Run the following components: -
62   &print_ident();
63   &include_osver();
# Line 42 | Line 72 | exit(0);
72  
73  
74  
45
46
47
48
75   # prints out an identifier for this version of statgrab.pl
76   # the host should check this when reading data
77   # means the host must be checked and updated to work with newer versions.
# Line 120 | Line 146 | sub include_users() {
146   sub include_top() {
147  
148      # Find out some numbers from top.
149 <    my(@top) = `$topbin -d2 -s1 0`;
149 >    my(@top) = `$topbin`;
150      my($top) = join(" ", @top);
151      $top =~ s/\n//g;
152  
153 <    &print_pair(0, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/);
154 <    &print_pair(0, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/);
155 <    &print_pair(0, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s/);
156 <    &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
157 <    &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
158 <    &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
159 <    &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
160 <    &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/);
161 <    &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
162 <    &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
163 <    &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/);
164 <    &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/);
165 <    &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
166 <
167 <    # The following need to be specified in megabytes.
168 <    # If they are preceeded by a G, then multiply by 1024.  
169 <
170 <    $top =~ /([^\s]+?)([MG]) real/;
171 <    my($real) = $1;
172 <    $real*=1024 if $2 eq "G";
173 <    &print_pair(0, "packet.memory.total", $real);
174 <
175 <    $top =~ /([^\s]+?)([MG]) free/;
176 <    my($free) = $1;
177 <    $free*=1024 if $2 eq "G";
178 <    &print_pair(0, "packet.memory.free", $free);
179 <
180 <    $top =~ /([^\s]+?)([MG]) swap in use/;
181 <    my($swap_in_use) = $1;
182 <    $swap_in_use*=1024 if $2 eq "G";
183 <    # DO NOT print this one out... save it for in a moment...
184 <
185 <    $top =~ /([^\s]+?)([MG]) swap free/;
186 <    my($swap_free) = $1;
187 <    $swap_free*=1024 if $2 eq "G";
188 <    &print_pair(0, "packet.swap.free", $swap_free);
189 <
190 <    # AJ requested total swap instead of swap_in_use, so here we go!
191 <    &print_pair(0, "packet.swap.total", $swap_free + $swap_in_use);
153 >    if($ostype eq "SunOS") {
154 >        &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
155 >        &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
156 >        &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
157 >        &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
158 >        &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/);
159 >        &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
160 >        &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
161 >        &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/);
162 >        &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/);
163 >        &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
164 >        
165 >        # The following need to be specified in megabytes.
166 >        # If they are preceeded by a G, then multiply by 1024.  
167 >        
168 >        $top =~ /([^\s]+?)([MG]) real/;
169 >        my($real) = $1;
170 >        $real*=1024 if $2 eq "G";
171 >        &print_pair(0, "packet.memory.total", $real);
172 >        
173 >        $top =~ /([^\s]+?)([MG]) free/;
174 >        my($free) = $1;
175 >        $free*=1024 if $2 eq "G";
176 >        &print_pair(0, "packet.memory.free", $free);
177 >        
178 >        $top =~ /([^\s]+?)([MG]) swap in use/;
179 >        my($swap_in_use) = $1;
180 >        $swap_in_use*=1024 if $2 eq "G";
181 >        # DO NOT print this one out... save it for in a moment...
182 >        
183 >        $top =~ /([^\s]+?)([MG]) swap free/;
184 >        my($swap_free) = $1;
185 >        $swap_free*=1024 if $2 eq "G";
186 >        &print_pair(0, "packet.swap.free", $swap_free);
187 >        
188 >        # AJ requested total swap instead of swap_in_use, so here we go!
189 >        &print_pair(0, "packet.swap.total", $swap_free + $swap_in_use);
190 >    }
191 >    elsif ($ostype eq "FreeBSD") {
192 >        &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
193 >        &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
194 >        &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
195 >        &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
196 >        &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/);
197 >        &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
198 >        &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
199 >        &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/);
200 >        &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/);
201 >        &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
202 >        
203 >        # The following need to be specified in megabytes.
204 >        # If they are preceeded by a G, then multiply by 1024.  
205 >        
206 >        # !! Can't get the total memory !!
207 >        #$top =~ /([^\s]+?)([MG]) real/;
208 >        #my($real) = $1;
209 >        #$real*=1024 if $2 eq "G";
210 >        #&print_pair(0, "packet.memory.total", $real);
211 >        &print_pair(0, "packet.memory.total", 0);
212 >        
213 >        $top =~ /([^\s]+?)([MG]) Free/;
214 >        my($free) = $1;
215 >        $free*=1024 if $2 eq "G";
216 >        &print_pair(0, "packet.memory.free", $free);
217 >        
218 >        $top =~ /Swap: ([^\s]+?)([MG]) Total/;
219 >        my($swap_total) = $1;
220 >        $swap_total*=1024 if $2 eq "G";
221 >        &print_pair(0, "packet.swap.total", $swap_total);
222 >        
223 >        $top =~ /Swap:.*, ([^\s]+?)([MG]) Free/;
224 >        my($swap_free) = $1;
225 >        $swap_free*=1024 if $2 eq "G";
226 >        &print_pair(0, "packet.swap.free", $swap_free);
227 >    }
228 >    elsif ($ostype eq "Linux") {
229 >        &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
230 >        &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
231 >        &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
232 >        &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
233 >        &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/);
234 >        &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
235 >        &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
236 >        &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/);
237 >        &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/);
238 >        &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
239 >        
240 >        # The following need to be specified in megabytes.
241 >        # If they are preceeded by a G, then multiply by 1024.  
242 >        
243 >        $top =~ / ([^\s]+?)([KMG]) av/;
244 >        my($real) = $1;
245 >        $real*=1024 if $2 eq "G";
246 >        $real/=1024 if $2 eq "K";
247 >        &print_pair(0, "packet.memory.total", int($real));
248 >        
249 >        $top =~ / ([^\s]+?)([KMG]) free/;
250 >        my($free) = $1;
251 >        $free*=1024 if $2 eq "G";
252 >        $free/=1024 if $2 eq "K";
253 >        &print_pair(0, "packet.memory.free", int($free));
254 >        
255 >        $top =~ /Swap:\s+([^\s]+?)([KMG]) av/;
256 >        my($swap_total) = $1;
257 >        $swap_total*=1024 if $2 eq "G";
258 >        $swap_total/=1024 if $2 eq "K";
259 >        &print_pair(0, "packet.swap.total", int($swap_total));
260 >        
261 >        $top =~ /Swap:.*, ([^\s]+?)([KMG]) free/;
262 >        my($swap_free) = $1;
263 >        $swap_free*=1024 if $2 eq "G";
264 >        $swap_free/=1024 if $2 eq "K";
265 >        &print_pair(0, "packet.swap.free", int($swap_free));
266 >    }
267 >    else {
268 >        # we could have some catchall here
269 >        # but as it stands this means we'll just skip top stuff
270 >        # for unknown systems
271 >    }
272   }
273  
274   # sub to get details of the machine's operating system.
# Line 185 | Line 291 | sub include_osver() {
291  
292   }
293  
294 < # sub to get system uptime.
294 > # sub to get system uptime in seconds.
295   sub include_uptime() {
296  
297      # debug stuff, all the different cases
# Line 207 | Line 313 | sub include_uptime() {
313  
314      # grab the uptime
315      my($uptime) = `$uptimebin`;
316 +    
317 +    &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
318 +    &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
319 +    &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
320  
321      # work out the days, hours, and minutes
322 <    if ($uptime =~ /hr/) {
323 <      # two possible cases here
324 <        if($uptime =~ /day/) {
325 <          # 0 minutes
326 <            $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
327 <            $uptime = "$1:$2:0";
322 >
323 >    if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) {
324 >      # normal
325 >        $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/;
326 >        $uptime = "$1:$2:$3";
327 >    }
328 >    else {
329 >        if ($uptime =~ /day/) {
330 >            if ($uptime =~ /hr/) {
331 >              # 0 minutes
332 >                $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
333 >                $uptime = "$1:$2:0";
334 >            }
335 >            elsif ($uptime =~ /min/) {
336 >              # 0 hours
337 >                $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
338 >                $uptime = "$1:0:$2";
339 >            }
340 >            else {
341 >              # 0 hours and 0 mins
342 >                $uptime =~ /up\s+([0-9]+)/;
343 >                $uptime = "$1:0:0";
344 >            }
345          }
346 <        else {
346 >        elsif ($uptime =~ /hr/) {
347            # 0 days and 0 minutes
348              $uptime =~ /up\s+([0-9]+)\s+/;
349              $uptime = "0:$1:0";
350          }
351 <    }
225 <    elsif ($uptime =~ /min/) {
226 <      # two possible cases here
227 <        if($uptime =~ /day/) {
228 <          # 0 hours
229 <            $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
230 <            $uptime = "$1:0:$2";
231 <        }
232 <        else {
351 >        elsif ($uptime =~ /min/) {
352            # 0 days and 0 hours
353              $uptime =~ /up\s+([0-9]+)\s+/;
354              $uptime = "0:0:$1";
355          }
237    }
238    elsif ($uptime =~ /day/) {
239        if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) {
240          # normal
241            $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/;
242            $uptime = "$1:$2:$3";
243        }
356          else {
357 <          # 0 hours and 0 mins
358 <            $uptime =~ /up\s+([0-9]+)/;
359 <            $uptime = "$1:0:0";
357 >          # 0 days
358 >            $uptime =~ /up\s+([0-9]+):([0-9]+)/;
359 >            $uptime = "0:$1:$2";
360          }
361      }
250    else {
251      # 0 days
252        $uptime =~ /up\s+([0-9]+):([0-9]+)/;
253        $uptime = "0:$1:$2";
254    }
362  
363 <    # turn into minutes
257 <
363 >    # turn into seconds
364      $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/;
365 <    $uptime = $3 + ($2 + $1*24)*60;
366 <
365 >    $uptime = ($3+($2+($1*24))*60)*60;
366 >    
367 >    # print the value out
368      &print_pair("unknown", "packet.os.uptime", $uptime);
369  
370   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines