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"; |
105 |
|
sub include_disk() { |
106 |
|
|
107 |
|
# Run the df program. |
108 |
< |
my(@df) = `$dfbin -ak`; |
108 |
> |
my(@df) = `$dfbin -akl`; |
109 |
|
|
110 |
|
# Go through each line of the program, looking for each thing we want. |
111 |
|
my($partition_no) = 0; |
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/); |
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]+?)([KMG]) 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]+?)([KMG]) 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]+?)([KMG]) 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]+?)([KMG]) 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 |
|
|
194 |
– |
# 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/); |
203 |
|
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); |
204 |
|
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
224 |
|
&print_pair(0, "packet.memory.total", $real); |
225 |
|
&print_pair(0, "packet.memory.free", $free); |
226 |
|
|
227 |
< |
$top =~ /Swap: ([^\s]+?)([KMG]) 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]+?)([KMG]) 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"; |
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/); |
253 |
– |
&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|total)/; |
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|total)/; |
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"; |