loadcheck: perltidy
This commit is contained in:
parent
2e356a7cab
commit
767a797dbd
@ -57,69 +57,73 @@ Written by Peter Eisch <peter@boku.net>.
|
||||
my $VERSION = 0.02;
|
||||
|
||||
sub register {
|
||||
my ($self, $qp, @args) = @_;
|
||||
my ($self, $qp, @args) = @_;
|
||||
|
||||
%{$self->{_args}} = @args;
|
||||
%{$self->{_args}} = @args;
|
||||
|
||||
$self->{_args}->{max_load} = 7
|
||||
if (! defined $self->{_args}->{max_load});
|
||||
$self->{_args}->{max_load} = 7
|
||||
if (!defined $self->{_args}->{max_load});
|
||||
|
||||
$self->{_args}->{uptime} = '/usr/bin/uptime'
|
||||
if (! defined $self->{_args}->{uptime});
|
||||
|
||||
$self->{_args}->{cache_time} = 10
|
||||
if (! defined $self->{_args}->{cache_time});
|
||||
$self->{_args}->{uptime} = '/usr/bin/uptime'
|
||||
if (!defined $self->{_args}->{uptime});
|
||||
|
||||
$self->{_load} = -1;
|
||||
$self->{_time} = 0;
|
||||
$self->{_args}->{cache_time} = 10
|
||||
if (!defined $self->{_args}->{cache_time});
|
||||
|
||||
$self->register_hook("connect", "loadcheck");
|
||||
$self->{_load} = -1;
|
||||
$self->{_time} = 0;
|
||||
|
||||
$self->register_hook("connect", "loadcheck");
|
||||
}
|
||||
|
||||
sub loadcheck {
|
||||
my ($self, $transaction) = @_;
|
||||
my ($self, $transaction) = @_;
|
||||
|
||||
if (time() > ($self->{_time} + $self->{_args}->{cache_time})) {
|
||||
# cached value expired
|
||||
if (time() > ($self->{_time} + $self->{_args}->{cache_time})) {
|
||||
|
||||
if ( -r '/kern/loadavg' ) { # *BSD
|
||||
# contains fix-point scaling value
|
||||
open(LD, "</kern/loadavg");
|
||||
my $res = <LD>;
|
||||
close LD;
|
||||
my @vals = split(/ /, $res);
|
||||
$self->{_load} = ($val[0] / $val[3]);
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG, "/kern/loadavg reported: $self->{_load}");
|
||||
} elsif ( -r '/proc/loadavg' ) { # *inux
|
||||
# contains decimal value
|
||||
# contains fix-point scaling value
|
||||
open(LD, "</proc/loadavg");
|
||||
my $res = <LD>;
|
||||
close LD;
|
||||
$self->{_load} = (split(/ /, $res))[0];
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG, "/proc/loadavg reported: $self->{_load}");
|
||||
} else {
|
||||
# the various formats returned:
|
||||
#10:33AM up 2:06, 1 user, load averages: 6.55, 3.76, 2.48
|
||||
# 12:29am 2 users, load average: 0.05, 0.05, 0.06
|
||||
# 12:30am up 5 days, 12:43, 1 user, load average: 0.00, 0.00, 0.00
|
||||
|
||||
my $res = `$self->{_args}->{uptime}`;
|
||||
if ($res =~ /aver\S+: (\d+\.\d+)/) {
|
||||
$self->{_load} = $1;
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG, "$self->{_args}->{uptime} reported: $self->{_load}");
|
||||
}
|
||||
}
|
||||
}
|
||||
# cached value expired
|
||||
|
||||
if ($self->{_load} > $self->{_args}->{max_load}) {
|
||||
$self->log(LOGERROR, "local load too high: $self->{_load}");
|
||||
return DENYSOFT;
|
||||
}
|
||||
if (-r '/kern/loadavg') { # *BSD
|
||||
# contains fix-point scaling value
|
||||
open(LD, "</kern/loadavg");
|
||||
my $res = <LD>;
|
||||
close LD;
|
||||
my @vals = split(/ /, $res);
|
||||
$self->{_load} = ($val[0] / $val[3]);
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG, "/kern/loadavg reported: $self->{_load}");
|
||||
}
|
||||
elsif (-r '/proc/loadavg') { # *inux
|
||||
# contains decimal value
|
||||
# contains fix-point scaling value
|
||||
open(LD, "</proc/loadavg");
|
||||
my $res = <LD>;
|
||||
close LD;
|
||||
$self->{_load} = (split(/ /, $res))[0];
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG, "/proc/loadavg reported: $self->{_load}");
|
||||
}
|
||||
else {
|
||||
# the various formats returned:
|
||||
#10:33AM up 2:06, 1 user, load averages: 6.55, 3.76, 2.48
|
||||
# 12:29am 2 users, load average: 0.05, 0.05, 0.06
|
||||
# 12:30am up 5 days, 12:43, 1 user, load average: 0.00, 0.00, 0.00
|
||||
|
||||
return (DECLINED, "continuing with load: $self->{_load}");
|
||||
my $res = `$self->{_args}->{uptime}`;
|
||||
if ($res =~ /aver\S+: (\d+\.\d+)/) {
|
||||
$self->{_load} = $1;
|
||||
$self->{_time} = time();
|
||||
$self->log(LOGDEBUG,
|
||||
"$self->{_args}->{uptime} reported: $self->{_load}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{_load} > $self->{_args}->{max_load}) {
|
||||
$self->log(LOGERROR, "local load too high: $self->{_load}");
|
||||
return DENYSOFT;
|
||||
}
|
||||
|
||||
return (DECLINED, "continuing with load: $self->{_load}");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user