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.26 by pjm2, Mon Feb 5 17:13:26 2001 UTC vs.
Revision 1.30 by tdb, Mon Feb 5 19:59:35 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";
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";
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";
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 124 | Line 150 | sub include_top() {
150      my($top) = join(" ", @top);
151      $top =~ s/\n//g;
152  
127    &print_pair(0, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/);
128    &print_pair(0, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/);
129    &print_pair(0, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s/);
153      &print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
154      &print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
155      &print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
# Line 185 | Line 208 | sub include_osver() {
208  
209   }
210  
211 < # sub to get system uptime.
211 > # sub to get system uptime in seconds.
212   sub include_uptime() {
213  
214 +    # debug stuff, all the different cases
215 +
216 +    # normal
217 +    #my($uptime) = "  4:48pm  up 49 day(s),  6:30,  201 users,  load average: 0.33, 0.35, 0.38\n";
218 +    # 0 days
219 +    #my($uptime) = "  4:48pm  up 6:30,  201 users,  load average: 0.33, 0.35, 0.38\n";
220 +    # 0 hours
221 +    #my($uptime) = "  4:48pm  up 49 day(s),  30 min(s),  201 users,  load average: 0.33, 0.35, 0.38\n";
222 +    # 0 mins
223 +    #my($uptime) = "  4:48pm  up 49 day(s),  6 hr(s),  201 users,  load average: 0.33, 0.35, 0.38\n";
224 +    # 0 days and 0 mins
225 +    #my($uptime) = "  4:48pm  up 6 hr(s),  201 users,  load average: 0.33, 0.35, 0.38\n";
226 +    # 0 days and 0 hours
227 +    #my($uptime) = "  4:48pm  up 30 min(s),  201 users,  load average: 0.33, 0.35, 0.38\n";
228 +    # 0 hours and 0 mins
229 +    #my($uptime) = "  4:48pm  up 49 day(s), 201 users,  load average: 0.33, 0.35, 0.38\n";
230 +
231      # grab the uptime
232      my($uptime) = `$uptimebin`;
233 +    
234 +    &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
235 +    &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
236 +    &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
237  
238      # work out the days, hours, and minutes
239 <    if ($uptime =~ /hr/) {
240 <      # 0 minutes
197 <        $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:$2:0/;
198 <    }
199 <    elsif ($uptime =~ /min/) {
200 <      # 0 hours
201 <        $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:0:$2/;
202 <    }
203 <    elsif ($uptime =~ /day/) {
239 >
240 >    if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) {
241        # normal
242 <        $uptime =~ s/up ([0-9]+) .*, ([0-9]+):([0-9]+)/$1:$2:$3/;
242 >        $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/;
243 >        $uptime = "$1:$2:$3";
244      }
245      else {
246 <      # 0 days
247 <        $uptime =~ s/up ([0-9]+):([0-9]+)/0:$1:$2/;
246 >        if ($uptime =~ /day/) {
247 >            if ($uptime =~ /hr/) {
248 >              # 0 minutes
249 >                $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
250 >                $uptime = "$1:$2:0";
251 >            }
252 >            elsif ($uptime =~ /min/) {
253 >              # 0 hours
254 >                $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/;
255 >                $uptime = "$1:0:$2";
256 >            }
257 >            else {
258 >              # 0 hours and 0 mins
259 >                $uptime =~ /up\s+([0-9]+)/;
260 >                $uptime = "$1:0:0";
261 >            }
262 >        }
263 >        elsif ($uptime =~ /hr/) {
264 >          # 0 days and 0 minutes
265 >            $uptime =~ /up\s+([0-9]+)\s+/;
266 >            $uptime = "0:$1:0";
267 >        }
268 >        elsif ($uptime =~ /min/) {
269 >          # 0 days and 0 hours
270 >            $uptime =~ /up\s+([0-9]+)\s+/;
271 >            $uptime = "0:0:$1";
272 >        }
273 >        else {
274 >          # 0 days
275 >            $uptime =~ /up\s+([0-9]+):([0-9]+)/;
276 >            $uptime = "0:$1:$2";
277 >        }
278      }
279  
280 <    # turn into minutes
213 <
280 >    # turn into seconds
281      $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/;
282 <    $uptime = $3 + ($2 + $1*24)*60;
283 <
282 >    $uptime = ($3+($2+($1*24))*60)*60;
283 >    
284 >    # print the value out
285      &print_pair("unknown", "packet.os.uptime", $uptime);
286  
287   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines