109 |
|
my($partition_no) = 0; |
110 |
|
for (my($i) = 0; $i < $#df; $i++) { |
111 |
|
my($line) = $df[$i]; |
112 |
< |
$line =~ /^(\/[^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; |
112 |
> |
$line =~ /^([^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; |
113 |
|
# $4 will not match unless everything before it does... |
114 |
|
if (defined $5) { |
115 |
|
my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); |
150 |
|
my($top) = join(" ", @top); |
151 |
|
$top =~ s/\n//g; |
152 |
|
|
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/); |
156 |
< |
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
157 |
< |
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); |
158 |
< |
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
159 |
< |
&print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
160 |
< |
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/); |
161 |
< |
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); |
162 |
< |
&print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
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.kernel", $top =~ /([^\s]+?)% system/); |
199 |
> |
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
200 |
> |
&print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
201 |
|
|
202 |
< |
# The following need to be specified in megabytes. |
203 |
< |
# If they are preceeded by a G, then multiply by 1024. |
204 |
< |
|
205 |
< |
$top =~ /([^\s]+?)([MG]) real/; |
206 |
< |
my($real) = $1; |
207 |
< |
$real*=1024 if $2 eq "G"; |
208 |
< |
&print_pair(0, "packet.memory.total", $real); |
209 |
< |
|
210 |
< |
$top =~ /([^\s]+?)([MG]) free/; |
211 |
< |
my($free) = $1; |
212 |
< |
$free*=1024 if $2 eq "G"; |
213 |
< |
&print_pair(0, "packet.memory.free", $free); |
214 |
< |
|
215 |
< |
$top =~ /([^\s]+?)([MG]) swap in use/; |
216 |
< |
my($swap_in_use) = $1; |
217 |
< |
$swap_in_use*=1024 if $2 eq "G"; |
218 |
< |
# DO NOT print this one out... save it for in a moment... |
219 |
< |
|
220 |
< |
$top =~ /([^\s]+?)([MG]) swap free/; |
221 |
< |
my($swap_free) = $1; |
222 |
< |
$swap_free*=1024 if $2 eq "G"; |
223 |
< |
&print_pair(0, "packet.swap.free", $swap_free); |
224 |
< |
|
225 |
< |
# AJ requested total swap instead of swap_in_use, so here we go! |
226 |
< |
&print_pair(0, "packet.swap.total", $swap_free + $swap_in_use); |
202 |
> |
# FreeBSD is a bit different, we need to get user and nice. |
203 |
> |
my($user) = 0; |
204 |
> |
if($top =~ /([^\s]+?)% user/) { $user += $1; } |
205 |
> |
if($top =~ /([^\s]+?)% nice/) { $user += $1; } |
206 |
> |
&print_pair(0, "packet.cpu.user", $user); |
207 |
> |
|
208 |
> |
# The following need to be specified in megabytes. |
209 |
> |
# If they are preceeded by a G, then multiply by 1024. |
210 |
> |
|
211 |
> |
# !! Can't get the total memory !! |
212 |
> |
#$top =~ /([^\s]+?)([MG]) real/; |
213 |
> |
#my($real) = $1; |
214 |
> |
#$real*=1024 if $2 eq "G"; |
215 |
> |
#&print_pair(0, "packet.memory.total", $real); |
216 |
> |
&print_pair(0, "packet.memory.total", 0); |
217 |
> |
|
218 |
> |
$top =~ /([^\s]+?)([MG]) Free/; |
219 |
> |
my($free) = $1; |
220 |
> |
$free*=1024 if $2 eq "G"; |
221 |
> |
&print_pair(0, "packet.memory.free", $free); |
222 |
> |
|
223 |
> |
$top =~ /Swap: ([^\s]+?)([MG]) Total/; |
224 |
> |
my($swap_total) = $1; |
225 |
> |
$swap_total*=1024 if $2 eq "G"; |
226 |
> |
&print_pair(0, "packet.swap.total", $swap_total); |
227 |
> |
|
228 |
> |
$top =~ /Swap:.*, ([^\s]+?)([MG]) Free/; |
229 |
> |
my($swap_free) = $1; |
230 |
> |
$swap_free*=1024 if $2 eq "G"; |
231 |
> |
&print_pair(0, "packet.swap.free", $swap_free); |
232 |
> |
} |
233 |
> |
elsif ($ostype eq "Linux") { |
234 |
> |
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
235 |
> |
&print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
236 |
> |
&print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
237 |
> |
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
238 |
> |
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/); |
239 |
> |
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
240 |
> |
&print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
241 |
> |
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); |
242 |
> |
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
243 |
> |
&print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
244 |
> |
|
245 |
> |
# The following need to be specified in megabytes. |
246 |
> |
# If they are preceeded by a G, then multiply by 1024. |
247 |
> |
|
248 |
> |
$top =~ / ([^\s]+?)([KMG]) av/; |
249 |
> |
my($real) = $1; |
250 |
> |
$real*=1024 if $2 eq "G"; |
251 |
> |
$real/=1024 if $2 eq "K"; |
252 |
> |
&print_pair(0, "packet.memory.total", int($real)); |
253 |
> |
|
254 |
> |
$top =~ / ([^\s]+?)([KMG]) free/; |
255 |
> |
my($free) = $1; |
256 |
> |
$free*=1024 if $2 eq "G"; |
257 |
> |
$free/=1024 if $2 eq "K"; |
258 |
> |
&print_pair(0, "packet.memory.free", int($free)); |
259 |
> |
|
260 |
> |
$top =~ /Swap:\s+([^\s]+?)([KMG]) av/; |
261 |
> |
my($swap_total) = $1; |
262 |
> |
$swap_total*=1024 if $2 eq "G"; |
263 |
> |
$swap_total/=1024 if $2 eq "K"; |
264 |
> |
&print_pair(0, "packet.swap.total", int($swap_total)); |
265 |
> |
|
266 |
> |
$top =~ /Swap:.*, ([^\s]+?)([KMG]) free/; |
267 |
> |
my($swap_free) = $1; |
268 |
> |
$swap_free*=1024 if $2 eq "G"; |
269 |
> |
$swap_free/=1024 if $2 eq "K"; |
270 |
> |
&print_pair(0, "packet.swap.free", int($swap_free)); |
271 |
> |
} |
272 |
> |
else { |
273 |
> |
# we could have some catchall here |
274 |
> |
# but as it stands this means we'll just skip top stuff |
275 |
> |
# for unknown systems |
276 |
> |
} |
277 |
|
} |
278 |
|
|
279 |
|
# sub to get details of the machine's operating system. |
327 |
|
|
328 |
|
if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { |
329 |
|
# normal |
330 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; |
330 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+):([0-9]+)/; |
331 |
|
$uptime = "$1:$2:$3"; |
332 |
|
} |
333 |
|
else { |
334 |
|
if ($uptime =~ /day/) { |
335 |
|
if ($uptime =~ /hr/) { |
336 |
|
# 0 minutes |
337 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
337 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; |
338 |
|
$uptime = "$1:$2:0"; |
339 |
|
} |
340 |
|
elsif ($uptime =~ /min/) { |
341 |
|
# 0 hours |
342 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
342 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; |
343 |
|
$uptime = "$1:0:$2"; |
344 |
|
} |
345 |
|
else { |