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

Comparing projects/cms/source/host/ihost-perl/plugins/perl/i-scream_uptime.pl (file contents):
Revision 1.2 by tdb, Tue Dec 18 04:07:17 2001 UTC vs.
Revision 1.3 by tdb, Tue Feb 12 17:14:56 2002 UTC

# Line 21 | Line 21 | $ostype = `uname -s` if not defined $ostype;
21   chomp($ostype);
22  
23   # Decide which paths we should use.
24 < my($uptimebin);
25 < if ($ostype eq "SunOS" || $ostype eq "Linux" || $ostype eq "FreeBSD") {
24 > my($uptimebin); my($sysctlbin);
25 > if ($ostype eq "SunOS" || $ostype eq "Linux") {
26      # covers: Solaris 7/8
27      # covers: Debian r2.2
28    # covers: FreeBSD 4.X
28      $uptimebin = "/usr/bin/uptime";
29   }
30 + elsif ($ostype eq "FreeBSD") {
31 +    # covers: FreeBSD 4.X
32 +    $sysctlbin = "/sbin/sysctl";
33 + }
34   else {
35      print "i-scream_uptime.pl Error: Unable to identify system type - \"$ostype\".\n";
36      print "\"uname -s\" does not report one of the following known types;\n";
# Line 65 | Line 68 | sub print_pair($$$) {
68   # get system uptime in seconds, and the current load
69   sub include_uptime() {
70  
71 <    # grab the uptime
72 <    my($uptime) = `$uptimebin`;
71 >    # if it's FreeBSD, get the uptime and load sanely :)
72 >    if ($ostype eq "FreeBSD") {
73 >        my($boottime) = `$sysctlbin -n kern.boottime`;
74 >        if($boottime =~ /^{ sec = (\d+),/) {
75 >            &print_pair("unknown", "packet.os.uptime", time()-$1);
76 >        }
77      
78 <    # grab the load
79 <    &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
80 <    &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
81 <    &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
82 <
83 <    # work out the days, hours, and minutes
77 <
78 <    if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) {
79 <      # normal
80 <        $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+):([0-9]+)/;
81 <        $uptime = "$1:$2:$3";
78 >        my($loadavg) = `$sysctlbin -n vm.loadavg`;
79 >        if($loadavg =~ /\s+([^\s]+?)\s+([^\s]+?)\s+([^\s]+?)\s+/) {
80 >            &print_pair(0, "packet.load.load1", $1);
81 >            &print_pair(0, "packet.load.load5", $2);
82 >            &print_pair(0, "packet.load.load15", $3);
83 >        }
84      }
85 +    
86 +    # otherwise, lets parse :)
87      else {
88 <        if ($uptime =~ /day/) {
89 <            if ($uptime =~ /hr/) {
90 <              # 0 minutes
91 <                $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/;
92 <                $uptime = "$1:$2:0";
88 >        # grab the uptime
89 >        my($uptime) = `$uptimebin`;
90 >        
91 >        # grab the load
92 >        &print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/);
93 >        &print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/);
94 >        &print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/);
95 >    
96 >        # work out the days, hours, and minutes
97 >    
98 >        if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) {
99 >          # normal
100 >            $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+):([0-9]+)/;
101 >            $uptime = "$1:$2:$3";
102 >        }
103 >        else {
104 >            if ($uptime =~ /day/) {
105 >                if ($uptime =~ /hr/) {
106 >                  # 0 minutes
107 >                    $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/;
108 >                    $uptime = "$1:$2:0";
109 >                }
110 >                elsif ($uptime =~ /min/) {
111 >                  # 0 hours
112 >                    $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/;
113 >                    $uptime = "$1:0:$2";
114 >                }
115 >                else {
116 >                  # 0 hours and 0 mins
117 >                    $uptime =~ /up\s+([0-9]+)/;
118 >                    $uptime = "$1:0:0";
119 >                }
120              }
121 +            elsif ($uptime =~ /hr/) {
122 +              # 0 days and 0 minutes
123 +                $uptime =~ /up\s+([0-9]+)\s+/;
124 +                $uptime = "0:$1:0";
125 +            }
126              elsif ($uptime =~ /min/) {
127 <              # 0 hours
128 <                $uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/;
129 <                $uptime = "$1:0:$2";
127 >              # 0 days and 0 hours
128 >                $uptime =~ /up\s+([0-9]+)\s+/;
129 >                $uptime = "0:0:$1";
130              }
131              else {
132 <              # 0 hours and 0 mins
133 <                $uptime =~ /up\s+([0-9]+)/;
134 <                $uptime = "$1:0:0";
132 >              # 0 days
133 >                $uptime =~ /up\s+([0-9]+):([0-9]+)/;
134 >                $uptime = "0:$1:$2";
135              }
136          }
101        elsif ($uptime =~ /hr/) {
102          # 0 days and 0 minutes
103            $uptime =~ /up\s+([0-9]+)\s+/;
104            $uptime = "0:$1:0";
105        }
106        elsif ($uptime =~ /min/) {
107          # 0 days and 0 hours
108            $uptime =~ /up\s+([0-9]+)\s+/;
109            $uptime = "0:0:$1";
110        }
111        else {
112          # 0 days
113            $uptime =~ /up\s+([0-9]+):([0-9]+)/;
114            $uptime = "0:$1:$2";
115        }
116    }
117
118    # turn into seconds
119    $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/;
120    $uptime = ($3+($2+($1*24))*60)*60;
137      
138 <    # print the value out
139 <    &print_pair("unknown", "packet.os.uptime", $uptime);
138 >        # turn into seconds
139 >        $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/;
140 >        $uptime = ($3+($2+($1*24))*60)*60;
141 >        
142 >        # print the value out
143 >        &print_pair("unknown", "packet.os.uptime", $uptime);
144 >    }
145  
146   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines