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.35 by tdb, Wed Feb 28 12:26:36 2001 UTC vs.
Revision 1.42 by pjm2, Wed Mar 21 10:51:32 2001 UTC

# Line 25 | Line 25 | use strict;
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);
28 > my($topbin); my($dfbin); my($usersbin);
29 > my($unamebin); my($uptimebin); my($sysctlbin);
30  
31   if ($ostype eq "SunOS") {
32      # covers: Solaris 8
# Line 37 | Line 38 | if ($ostype eq "SunOS") {
38   }
39   elsif ($ostype eq "Linux") {
40      # covers: Debian r2.2
41 <    $topbin = "/usr/bin/top -d1 -n0 -b";
41 >    $topbin = "/usr/bin/top -d1 -n2 -b -p0";
42      $dfbin = "/bin/df";
43      $usersbin = "/usr/bin/users";
44      $unamebin = "/bin/uname";
# Line 50 | Line 51 | elsif ($ostype eq "FreeBSD") {
51      $usersbin = "/usr/bin/users";
52      $unamebin = "/usr/bin/uname";
53      $uptimebin = "/usr/bin/uptime";
54 +    $sysctlbin = "/sbin/sysctl";
55   }
56   else {
57      print "statgrab.pl Error: Unable to identify system type - \"$ostype\".\n";
# Line 148 | Line 150 | sub include_top() {
150      # Find out some numbers from top.
151      my(@top) = `$topbin`;
152      my($top) = join(" ", @top);
153 <    $top =~ s/\n//g;
153 >    $top =~ s/\n/ /g;
154  
155      if($ostype eq "SunOS") {
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/);
156 >        &print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/);
157 >        &print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/);
158 >        &print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/);
159 >        &print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/);
160 >        &print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\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/);
# Line 165 | Line 167 | sub include_top() {
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/;
170 >        $top =~ /([0-9]+?)([KMG]) real/;
171          my($real) = $1;
172          $real*=1024 if $2 eq "G";
173 +        $real/=1024 if $2 eq "K";
174          &print_pair(0, "packet.memory.total", $real);
175          
176 <        $top =~ /([^\s]+?)([MG]) free/;
176 >        $top =~ /([0-9]+?)([KMG]) free/;
177          my($free) = $1;
178          $free*=1024 if $2 eq "G";
179 +        $free/=1024 if $2 eq "K";
180          &print_pair(0, "packet.memory.free", $free);
181          
182 <        $top =~ /([^\s]+?)([MG]) swap in use/;
182 >        $top =~ /([0-9]+?)([KMG]) swap in use/;
183          my($swap_in_use) = $1;
184          $swap_in_use*=1024 if $2 eq "G";
185 +        $swap_in_use/=1024 if $2 eq "K";
186          # DO NOT print this one out... save it for in a moment...
187          
188 <        $top =~ /([^\s]+?)([MG]) swap free/;
188 >        $top =~ /([0-9]+?)([KMG]) swap free/;
189          my($swap_free) = $1;
190          $swap_free*=1024 if $2 eq "G";
191 +        $swap_free/=1024 if $2 eq "K";
192          &print_pair(0, "packet.swap.free", $swap_free);
193          
188        # AJ requested total swap instead of swap_in_use, so here we go!
194          &print_pair(0, "packet.swap.total", $swap_free + $swap_in_use);
195      }
196      elsif ($ostype eq "FreeBSD") {
197 <        &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
198 <        &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
199 <        &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
200 <        &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
201 <        &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/);
197 >        &print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/);
198 >        &print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/);
199 >        &print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/);
200 >        &print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/);
201 >        &print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\s*running/);
202          &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
198        &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
203          &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/);
204          &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/);
205          &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
206 +
207 +        # FreeBSD is a bit different, we need to get user and nice.
208 +        my($user) = 0;
209 +        if($top =~ /([^\s]+?)% user/) { $user += $1; }
210 +        if($top =~ /([^\s]+?)% nice/) { $user += $1; }
211 +        &print_pair(0, "packet.cpu.user", $user);
212          
213          # The following need to be specified in megabytes.
214          # If they are preceeded by a G, then multiply by 1024.  
215          
216 <        # !! Can't get the total memory !!
217 <        #$top =~ /([^\s]+?)([MG]) real/;
218 <        #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);
216 >        # get RAM slightly differently
217 >        my($real) = `$sysctlbin -n hw.physmem`;
218 >        my($free) = $real - `$sysctlbin -n hw.usermem`;
219          
220 <        $top =~ /([^\s]+?)([MG]) Free/;
221 <        my($free) = $1;
222 <        $free*=1024 if $2 eq "G";
220 >        # turn bytes to megabytes
221 >        $real = ($real / 1024) / 1024;
222 >        $free = ($free / 1024) / 1024;
223 >        
224 >        &print_pair(0, "packet.memory.total", $real);
225          &print_pair(0, "packet.memory.free", $free);
226          
227 <        $top =~ /Swap: ([^\s]+?)([MG]) Total/;
227 >        $top =~ /Swap: ([0-9]+?)([KMG]) Total/;
228          my($swap_total) = $1;
229          $swap_total*=1024 if $2 eq "G";
230 +        $swap_total/=1024 if $2 eq "K";
231          &print_pair(0, "packet.swap.total", $swap_total);
232          
233 <        $top =~ /Swap:.*, ([^\s]+?)([MG]) Free/;
233 >        $top =~ /Swap:.*, ([0-9]+?)([KMG]) Free/;
234          my($swap_free) = $1;
235          $swap_free*=1024 if $2 eq "G";
236 +        $swap_free/=1024 if $2 eq "K";
237          &print_pair(0, "packet.swap.free", $swap_free);
238 +        
239 +        my($loads) = `$sysctlbin -n vm.loadavg`;
240 +        $loads =~ /\s+([^\s]+?)\s+([^\s]+?)\s+([^\s]+?)\s+/;
241 +        &print_pair(0, "packet.load.load1", $1);
242 +        &print_pair(0, "packet.load.load5", $2);
243 +        &print_pair(0, "packet.load.load15", $3);
244      }
245      elsif ($ostype eq "Linux") {
246 <        &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
247 <        &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
248 <        &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
249 <        &print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/);
250 <        &print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/);
246 >        my ($top) = "";
247 >        foreach my $line (@top) {
248 >            $top = $line . $top;
249 >        }
250 >        $top =~ s/\n/ /g;
251 >
252 >        &print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/);
253 >        &print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/);
254 >        &print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/);
255 >        &print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/);
256 >        &print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\s*running/);
257          &print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/);
235        &print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/);
258          &print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/);
259          &print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/);
260          &print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/);
261 +
262 +        # FreeBSD is a bit different, we need to get user and nice.
263 +        my($user) = 0;
264 +        if($top =~ /([^\s]+?)% user/) { $user += $1; }
265 +        if($top =~ /([^\s]+?)% nice/) { $user += $1; }
266 +        &print_pair(0, "packet.cpu.user", $user);
267          
268          # The following need to be specified in megabytes.
269          # If they are preceeded by a G, then multiply by 1024.  
270          
271 <        $top =~ / ([^\s]+?)([KMG]) av/;
271 >        $top =~ /Mem:.*?([0-9]+)([KMG])\s+av/;
272          my($real) = $1;
273          $real*=1024 if $2 eq "G";
274          $real/=1024 if $2 eq "K";
275          &print_pair(0, "packet.memory.total", int($real));
276          
277 <        $top =~ / ([^\s]+?)([KMG]) free/;
277 >        $top =~ /Mem:.*?([0-9]+)([KMG])\s+free/;
278          my($free) = $1;
279          $free*=1024 if $2 eq "G";
280          $free/=1024 if $2 eq "K";
281          &print_pair(0, "packet.memory.free", int($free));
282          
283 <        $top =~ /Swap:\s+([^\s]+?)([KMG]) av/;
283 >        $top =~ /Swap:.*?([0-9]]+)([KMG])\s+av/;
284          my($swap_total) = $1;
285          $swap_total*=1024 if $2 eq "G";
286          $swap_total/=1024 if $2 eq "K";
287          &print_pair(0, "packet.swap.total", int($swap_total));
288          
289 <        $top =~ /Swap:.*, ([^\s]+?)([KMG]) free/;
289 >        $top =~ /Swap:.*?([0-9]+)([KMG])\s+free/;
290          my($swap_free) = $1;
291          $swap_free*=1024 if $2 eq "G";
292          $swap_free/=1024 if $2 eq "K";
# Line 314 | Line 342 | sub include_uptime() {
342      # grab the uptime
343      my($uptime) = `$uptimebin`;
344      
345 <    &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
346 <    &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
347 <    &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
345 >    if($ostype ne "FreeBSD") {
346 >        &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
347 >        &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
348 >        &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
349 >    }
350  
351      # work out the days, hours, and minutes
352  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines