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); |
28 |
> |
my($topbin); my($dfbin); my($usersbin); |
29 |
> |
my($unamebin); my($uptimebin); my($sysctlbin); |
30 |
|
|
31 |
|
if ($ostype eq "SunOS") { |
32 |
|
# covers: Solaris 8 |
51 |
|
$usersbin = "/usr/bin/users"; |
52 |
|
$unamebin = "/usr/bin/uname"; |
53 |
|
$uptimebin = "/usr/bin/uptime"; |
54 |
+ |
$sysctlbin = "/sbin/sysctl"; |
55 |
|
} |
56 |
|
else { |
57 |
|
print "statgrab.pl Error: Unable to identify system type - \"$ostype\".\n"; |
111 |
|
my($partition_no) = 0; |
112 |
|
for (my($i) = 0; $i < $#df; $i++) { |
113 |
|
my($line) = $df[$i]; |
114 |
< |
$line =~ /^(\/[^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; |
114 |
> |
$line =~ /^([^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/; |
115 |
|
# $4 will not match unless everything before it does... |
116 |
|
if (defined $5) { |
117 |
|
my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); |
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]+?)([MG]) real/; |
170 |
> |
$top =~ /([^\s]+?)([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]+?)([MG]) free/; |
176 |
> |
$top =~ /([^\s]+?)([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]+?)([MG]) swap in use/; |
182 |
> |
$top =~ /([^\s]+?)([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]+?)([MG]) swap free/; |
188 |
> |
$top =~ /([^\s]+?)([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! |
201 |
|
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
202 |
|
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/); |
203 |
|
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
198 |
– |
&print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
204 |
|
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); |
205 |
|
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
206 |
|
&print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
207 |
+ |
|
208 |
+ |
# FreeBSD is a bit different, we need to get user and nice. |
209 |
+ |
my($user) = 0; |
210 |
+ |
if($top =~ /([^\s]+?)% user/) { $user += $1; } |
211 |
+ |
if($top =~ /([^\s]+?)% nice/) { $user += $1; } |
212 |
+ |
&print_pair(0, "packet.cpu.user", $user); |
213 |
|
|
214 |
|
# The following need to be specified in megabytes. |
215 |
|
# If they are preceeded by a G, then multiply by 1024. |
216 |
|
|
217 |
< |
# !! Can't get the total memory !! |
218 |
< |
#$top =~ /([^\s]+?)([MG]) real/; |
219 |
< |
#my($real) = $1; |
209 |
< |
#$real*=1024 if $2 eq "G"; |
210 |
< |
#&print_pair(0, "packet.memory.total", $real); |
211 |
< |
&print_pair(0, "packet.memory.total", 0); |
217 |
> |
# get RAM slightly differently |
218 |
> |
my($real) = `$sysctlbin -n hw.physmem`; |
219 |
> |
my($free) = $real - `$sysctlbin -n hw.usermem`; |
220 |
|
|
221 |
< |
$top =~ /([^\s]+?)([MG]) Free/; |
222 |
< |
my($free) = $1; |
223 |
< |
$free*=1024 if $2 eq "G"; |
221 |
> |
# turn bytes to megabytes |
222 |
> |
$real = ($real / 1024) / 1024; |
223 |
> |
$free = ($free / 1024) / 1024; |
224 |
> |
|
225 |
> |
&print_pair(0, "packet.memory.total", $real); |
226 |
|
&print_pair(0, "packet.memory.free", $free); |
227 |
|
|
228 |
< |
$top =~ /Swap: ([^\s]+?)([MG]) Total/; |
228 |
> |
$top =~ /Swap: ([^\s]+?)([KMG]) Total/; |
229 |
|
my($swap_total) = $1; |
230 |
|
$swap_total*=1024 if $2 eq "G"; |
231 |
+ |
$swap_total/=1024 if $2 eq "K"; |
232 |
|
&print_pair(0, "packet.swap.total", $swap_total); |
233 |
|
|
234 |
< |
$top =~ /Swap:.*, ([^\s]+?)([MG]) Free/; |
234 |
> |
$top =~ /Swap:.*, ([^\s]+?)([KMG]) Free/; |
235 |
|
my($swap_free) = $1; |
236 |
|
$swap_free*=1024 if $2 eq "G"; |
237 |
+ |
$swap_free/=1024 if $2 eq "K"; |
238 |
|
&print_pair(0, "packet.swap.free", $swap_free); |
239 |
+ |
|
240 |
+ |
my($loads) = `$sysctlbin -n vm.loadavg`; |
241 |
+ |
$loads =~ /\s+([^\s]+?)\s+([^\s]+?)\s+([^\s]+?)\s+/; |
242 |
+ |
&print_pair(0, "packet.load.load1", $1); |
243 |
+ |
&print_pair(0, "packet.load.load5", $2); |
244 |
+ |
&print_pair(0, "packet.load.load15", $3); |
245 |
|
} |
246 |
|
elsif ($ostype eq "Linux") { |
247 |
|
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
332 |
|
# grab the uptime |
333 |
|
my($uptime) = `$uptimebin`; |
334 |
|
|
335 |
< |
&print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/); |
336 |
< |
&print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/); |
337 |
< |
&print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/); |
335 |
> |
if($ostype ne "FreeBSD") { |
336 |
> |
&print_pair(0, "packet.load.load1", $uptime =~ /load average.?:\s*([^\s]+?),/); |
337 |
> |
&print_pair(0, "packet.load.load5", $uptime =~ /load average.?:\s*.+?,\s*([^\s]+?),/); |
338 |
> |
&print_pair(0, "packet.load.load15", $uptime =~ /load average.?:\s*.+?,\s*.+?,\s*([^\s]+)/); |
339 |
> |
} |
340 |
|
|
341 |
|
# work out the days, hours, and minutes |
342 |
|
|
343 |
|
if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { |
344 |
|
# normal |
345 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; |
345 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+):([0-9]+)/; |
346 |
|
$uptime = "$1:$2:$3"; |
347 |
|
} |
348 |
|
else { |
349 |
|
if ($uptime =~ /day/) { |
350 |
|
if ($uptime =~ /hr/) { |
351 |
|
# 0 minutes |
352 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
352 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; |
353 |
|
$uptime = "$1:$2:0"; |
354 |
|
} |
355 |
|
elsif ($uptime =~ /min/) { |
356 |
|
# 0 hours |
357 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
357 |
> |
$uptime =~ /up\s+([0-9]+)\s+[^\s]+,\s+([0-9]+)\s+[^\s]+,/; |
358 |
|
$uptime = "$1:0:$2"; |
359 |
|
} |
360 |
|
else { |