124 |
|
my($top) = join(" ", @top); |
125 |
|
$top =~ s/\n//g; |
126 |
|
|
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/); |
127 |
|
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
128 |
|
&print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
129 |
|
&print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
182 |
|
|
183 |
|
} |
184 |
|
|
185 |
< |
# sub to get system uptime. |
185 |
> |
# sub to get system uptime in seconds. |
186 |
|
sub include_uptime() { |
187 |
|
|
188 |
|
# debug stuff, all the different cases |
204 |
|
|
205 |
|
# grab the uptime |
206 |
|
my($uptime) = `$uptimebin`; |
207 |
+ |
|
208 |
+ |
&print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/); |
209 |
+ |
&print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/); |
210 |
+ |
&print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/); |
211 |
|
|
212 |
|
# work out the days, hours, and minutes |
213 |
< |
if ($uptime =~ /hr/) { |
214 |
< |
# two possible cases here |
215 |
< |
if($uptime =~ /day/) { |
216 |
< |
# 0 minutes |
217 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
218 |
< |
$uptime = "$1:$2:0"; |
213 |
> |
|
214 |
> |
if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { |
215 |
> |
# normal |
216 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; |
217 |
> |
$uptime = "$1:$2:$3"; |
218 |
> |
} |
219 |
> |
else { |
220 |
> |
if ($uptime =~ /day/) { |
221 |
> |
if ($uptime =~ /hr/) { |
222 |
> |
# 0 minutes |
223 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
224 |
> |
$uptime = "$1:$2:0"; |
225 |
> |
} |
226 |
> |
elsif ($uptime =~ /min/) { |
227 |
> |
# 0 hours |
228 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
229 |
> |
$uptime = "$1:0:$2"; |
230 |
> |
} |
231 |
> |
else { |
232 |
> |
# 0 hours and 0 mins |
233 |
> |
$uptime =~ /up\s+([0-9]+)/; |
234 |
> |
$uptime = "$1:0:0"; |
235 |
> |
} |
236 |
|
} |
237 |
< |
else { |
237 |
> |
elsif ($uptime =~ /hr/) { |
238 |
|
# 0 days and 0 minutes |
239 |
|
$uptime =~ /up\s+([0-9]+)\s+/; |
240 |
|
$uptime = "0:$1:0"; |
241 |
|
} |
242 |
< |
} |
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 { |
242 |
> |
elsif ($uptime =~ /min/) { |
243 |
|
# 0 days and 0 hours |
244 |
|
$uptime =~ /up\s+([0-9]+)\s+/; |
245 |
|
$uptime = "0:0:$1"; |
246 |
|
} |
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 |
– |
} |
247 |
|
else { |
248 |
< |
# 0 hours and 0 mins |
249 |
< |
$uptime =~ /up\s+([0-9]+)/; |
250 |
< |
$uptime = "$1:0:0"; |
248 |
> |
# 0 days |
249 |
> |
$uptime =~ /up\s+([0-9]+):([0-9]+)/; |
250 |
> |
$uptime = "0:$1:$2"; |
251 |
|
} |
252 |
|
} |
250 |
– |
else { |
251 |
– |
# 0 days |
252 |
– |
$uptime =~ /up\s+([0-9]+):([0-9]+)/; |
253 |
– |
$uptime = "0:$1:$2"; |
254 |
– |
} |
253 |
|
|
254 |
< |
# turn into minutes |
257 |
< |
|
254 |
> |
# turn into seconds |
255 |
|
$uptime =~ /([0-9]+):([0-9]+):([0-9]+)/; |
256 |
< |
$uptime = $3 + ($2 + $1*24)*60; |
257 |
< |
|
256 |
> |
$uptime = ($3+($2+($1*24))*60)*60; |
257 |
> |
|
258 |
> |
# print the value out |
259 |
|
&print_pair("unknown", "packet.os.uptime", $uptime); |
260 |
|
|
261 |
|
} |