| 1 |
|
#!/usr/bin/perl -w |
| 2 |
|
|
| 3 |
+ |
# |
| 4 |
+ |
# i-scream central monitoring system |
| 5 |
+ |
# http://www.i-scream.org.uk |
| 6 |
+ |
# Copyright (C) 2000-2002 i-scream |
| 7 |
+ |
# |
| 8 |
+ |
# This program is free software; you can redistribute it and/or |
| 9 |
+ |
# modify it under the terms of the GNU General Public License |
| 10 |
+ |
# as published by the Free Software Foundation; either version 2 |
| 11 |
+ |
# of the License, or (at your option) any later version. |
| 12 |
+ |
# |
| 13 |
+ |
# This program is distributed in the hope that it will be useful, |
| 14 |
+ |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
+ |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
+ |
# GNU General Public License for more details. |
| 17 |
+ |
# |
| 18 |
+ |
# You should have received a copy of the GNU General Public License |
| 19 |
+ |
# along with this program; if not, write to the Free Software |
| 20 |
+ |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
+ |
# |
| 22 |
+ |
|
| 23 |
|
#----------------------------------------------------------------- |
| 24 |
|
# Machine statistics grabber |
| 25 |
|
# $Author$ |
| 58 |
|
} |
| 59 |
|
elsif ($ostype eq "Linux") { |
| 60 |
|
# covers: Debian r2.2 |
| 61 |
< |
$topbin = "/usr/bin/top -d1 -n0 -b"; |
| 61 |
> |
$topbin = "/usr/bin/top -d1 -n2 -b -p0"; |
| 62 |
|
$dfbin = "/bin/df"; |
| 63 |
|
$usersbin = "/usr/bin/users"; |
| 64 |
|
$unamebin = "/bin/uname"; |
| 98 |
|
# the host should check this when reading data |
| 99 |
|
# means the host must be checked and updated to work with newer versions. |
| 100 |
|
sub print_ident() { |
| 101 |
< |
print 'version statgrab.pl $Revision$'; |
| 101 |
> |
print 'packet.version statgrab.pl $Revision$'; |
| 102 |
|
print "\n"; |
| 103 |
|
} |
| 104 |
|
|
| 125 |
|
sub include_disk() { |
| 126 |
|
|
| 127 |
|
# Run the df program. |
| 128 |
< |
my(@df) = `$dfbin -ak`; |
| 128 |
> |
my(@df) = `$dfbin -akl`; |
| 129 |
|
|
| 130 |
|
# Go through each line of the program, looking for each thing we want. |
| 131 |
|
my($partition_no) = 0; |
| 170 |
|
# Find out some numbers from top. |
| 171 |
|
my(@top) = `$topbin`; |
| 172 |
|
my($top) = join(" ", @top); |
| 173 |
< |
$top =~ s/\n//g; |
| 173 |
> |
$top =~ s/\n/ /g; |
| 174 |
|
|
| 175 |
|
if($ostype eq "SunOS") { |
| 176 |
< |
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
| 177 |
< |
&print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
| 178 |
< |
&print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
| 179 |
< |
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
| 180 |
< |
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); |
| 176 |
> |
&print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/); |
| 177 |
> |
&print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/); |
| 178 |
> |
&print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/); |
| 179 |
> |
&print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/); |
| 180 |
> |
&print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\s*on cpu/); |
| 181 |
|
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
| 182 |
|
&print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
| 183 |
|
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/); |
| 187 |
|
# The following need to be specified in megabytes. |
| 188 |
|
# If they are preceeded by a G, then multiply by 1024. |
| 189 |
|
|
| 190 |
< |
$top =~ /([^\s]+?)([KMG]) real/; |
| 190 |
> |
$top =~ /([0-9]+?)([KMG]) real/; |
| 191 |
|
my($real) = $1; |
| 192 |
|
$real*=1024 if $2 eq "G"; |
| 193 |
|
$real/=1024 if $2 eq "K"; |
| 194 |
|
&print_pair(0, "packet.memory.total", $real); |
| 195 |
|
|
| 196 |
< |
$top =~ /([^\s]+?)([KMG]) free/; |
| 196 |
> |
$top =~ /([0-9]+?)([KMG]) free/; |
| 197 |
|
my($free) = $1; |
| 198 |
|
$free*=1024 if $2 eq "G"; |
| 199 |
|
$free/=1024 if $2 eq "K"; |
| 200 |
|
&print_pair(0, "packet.memory.free", $free); |
| 201 |
|
|
| 202 |
< |
$top =~ /([^\s]+?)([KMG]) swap in use/; |
| 202 |
> |
$top =~ /([0-9]+?)([KMG]) swap in use/; |
| 203 |
|
my($swap_in_use) = $1; |
| 204 |
|
$swap_in_use*=1024 if $2 eq "G"; |
| 205 |
|
$swap_in_use/=1024 if $2 eq "K"; |
| 206 |
|
# DO NOT print this one out... save it for in a moment... |
| 207 |
|
|
| 208 |
< |
$top =~ /([^\s]+?)([KMG]) swap free/; |
| 208 |
> |
$top =~ /([0-9]+?)([KMG]) swap free/; |
| 209 |
|
my($swap_free) = $1; |
| 210 |
|
$swap_free*=1024 if $2 eq "G"; |
| 211 |
|
$swap_free/=1024 if $2 eq "K"; |
| 212 |
|
&print_pair(0, "packet.swap.free", $swap_free); |
| 213 |
|
|
| 194 |
– |
# AJ requested total swap instead of swap_in_use, so here we go! |
| 214 |
|
&print_pair(0, "packet.swap.total", $swap_free + $swap_in_use); |
| 215 |
|
} |
| 216 |
|
elsif ($ostype eq "FreeBSD") { |
| 217 |
< |
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
| 218 |
< |
&print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
| 219 |
< |
&print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
| 220 |
< |
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
| 221 |
< |
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/); |
| 217 |
> |
&print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/); |
| 218 |
> |
&print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/); |
| 219 |
> |
&print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/); |
| 220 |
> |
&print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/); |
| 221 |
> |
&print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\s*running/); |
| 222 |
|
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
| 223 |
|
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); |
| 224 |
|
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
| 244 |
|
&print_pair(0, "packet.memory.total", $real); |
| 245 |
|
&print_pair(0, "packet.memory.free", $free); |
| 246 |
|
|
| 247 |
< |
$top =~ /Swap: ([^\s]+?)([KMG]) Total/; |
| 247 |
> |
$top =~ /Swap: ([0-9]+?)([KMG]) Total/; |
| 248 |
|
my($swap_total) = $1; |
| 249 |
|
$swap_total*=1024 if $2 eq "G"; |
| 250 |
|
$swap_total/=1024 if $2 eq "K"; |
| 251 |
|
&print_pair(0, "packet.swap.total", $swap_total); |
| 252 |
|
|
| 253 |
< |
$top =~ /Swap:.*, ([^\s]+?)([KMG]) Free/; |
| 253 |
> |
$top =~ /Swap:.*, ([0-9]+?)([KMG]) Free/; |
| 254 |
|
my($swap_free) = $1; |
| 255 |
|
$swap_free*=1024 if $2 eq "G"; |
| 256 |
|
$swap_free/=1024 if $2 eq "K"; |
| 263 |
|
&print_pair(0, "packet.load.load15", $3); |
| 264 |
|
} |
| 265 |
|
elsif ($ostype eq "Linux") { |
| 266 |
< |
&print_pair(0, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
| 267 |
< |
&print_pair(0, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
| 268 |
< |
&print_pair(0, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
| 269 |
< |
&print_pair(0, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
| 270 |
< |
&print_pair(0, "packet.processes.cpu", $top =~ /([^\s]+?)\s*running/); |
| 266 |
> |
my ($top) = ""; |
| 267 |
> |
foreach my $line (@top) { |
| 268 |
> |
$top = $line . $top; |
| 269 |
> |
} |
| 270 |
> |
$top =~ s/\n/ /g; |
| 271 |
> |
|
| 272 |
> |
&print_pair(0, "packet.processes.total", $top =~ /([0-9]+?) processes:/); |
| 273 |
> |
&print_pair(0, "packet.processes.sleeping", $top =~ /([0-9]+?) sleeping/); |
| 274 |
> |
&print_pair(0, "packet.processes.zombie", $top =~ /([0-9]+?) zombie/); |
| 275 |
> |
&print_pair(0, "packet.processes.stopped", $top =~ /([0-9]+?) stopped/); |
| 276 |
> |
&print_pair(0, "packet.processes.cpu", $top =~ /([0-9]+?)\s*running/); |
| 277 |
|
&print_pair(0, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
| 253 |
– |
&print_pair(0, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
| 278 |
|
&print_pair(0, "packet.cpu.kernel", $top =~ /([^\s]+?)% system/); |
| 279 |
|
&print_pair(0, "packet.cpu.iowait", $top =~ /([^\s]+?)% interrupt/); |
| 280 |
|
&print_pair(0, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
| 281 |
+ |
|
| 282 |
+ |
# FreeBSD is a bit different, we need to get user and nice. |
| 283 |
+ |
my($user) = 0; |
| 284 |
+ |
if($top =~ /([^\s]+?)% user/) { $user += $1; } |
| 285 |
+ |
if($top =~ /([^\s]+?)% nice/) { $user += $1; } |
| 286 |
+ |
&print_pair(0, "packet.cpu.user", $user); |
| 287 |
|
|
| 288 |
|
# The following need to be specified in megabytes. |
| 289 |
|
# If they are preceeded by a G, then multiply by 1024. |
| 290 |
|
|
| 291 |
< |
$top =~ / ([^\s]+?)([KMG]) av/; |
| 291 |
> |
$top =~ /Mem:.*?([0-9]+)([KMG])\s+(av|total)/; |
| 292 |
|
my($real) = $1; |
| 293 |
|
$real*=1024 if $2 eq "G"; |
| 294 |
|
$real/=1024 if $2 eq "K"; |
| 295 |
|
&print_pair(0, "packet.memory.total", int($real)); |
| 296 |
|
|
| 297 |
< |
$top =~ / ([^\s]+?)([KMG]) free/; |
| 297 |
> |
$top =~ /Mem:.*?([0-9]+)([KMG])\s+free/; |
| 298 |
|
my($free) = $1; |
| 299 |
|
$free*=1024 if $2 eq "G"; |
| 300 |
|
$free/=1024 if $2 eq "K"; |
| 301 |
|
&print_pair(0, "packet.memory.free", int($free)); |
| 302 |
|
|
| 303 |
< |
$top =~ /Swap:\s+([^\s]+?)([KMG]) av/; |
| 303 |
> |
$top =~ /Swap:.*?([0-9]+)([KMG])\s+(av|total)/; |
| 304 |
|
my($swap_total) = $1; |
| 305 |
|
$swap_total*=1024 if $2 eq "G"; |
| 306 |
|
$swap_total/=1024 if $2 eq "K"; |
| 307 |
|
&print_pair(0, "packet.swap.total", int($swap_total)); |
| 308 |
|
|
| 309 |
< |
$top =~ /Swap:.*, ([^\s]+?)([KMG]) free/; |
| 309 |
> |
$top =~ /Swap:.*?([0-9]+)([KMG])\s+free/; |
| 310 |
|
my($swap_free) = $1; |
| 311 |
|
$swap_free*=1024 if $2 eq "G"; |
| 312 |
|
$swap_free/=1024 if $2 eq "K"; |