Heh.. Sadly, I never thought of that ;)  But that does tend to make more
sense.

Ed


On Thu, 26 Jan 2006 23:55:58 -0600, Peter Eisch wrote:

> On 1/26/06 10:42 PM, "Robert Spier" <[EMAIL PROTECTED]> wrote:
> 
>> I'm sure there is a module that
>> someone has written that abstracts this all away.
> 
> Sorry for the text inline, I'm somewhat encumbered at the moment:
> 
> #!/usr/bin/perl
> 
> =head1 NAME
> 
> loadcheck
> 
> =head1 DESCRIPTION
> 
> Only takes email transactions if the system load is at or below a
> specified level.  
> 
> =head1 CONFIG
> 
> max_load
> 
>   This is the 1 minute system load where we won't take transactions
> if our load is higher than this value.  (Default: 7)
> 
> uptime
> 
>   The path to the command 'uptime' if different than the default.
> (Default: /usr/bin/uptime)
> 
> Example:
> 
> loadcheck max_load 7 uptime /usr/bin/uptime
> 
> =over 4
> 
> =head1 AUTHOR
> 
> Written by Peter Eisch <[EMAIL PROTECTED]>.
> 
> =cut
> 
> my $VERSION = 0.01;
> 
> sub register {
>   my ($self, $qp, @args) = @_;
> 
>   %{$self->{_args}} = @args;
> 
>   $self->{_args}->{max_load} = 7
>       if (! defined $self->{_args}->{max_load});
> 
>   $self->{_args}->{uptime} = '/usr/bin/uptime'
>       if (! defined $self->{_args}->{uptime});
>   
>   $self->register_hook("connect", "loadcheck");
> }
> 
> sub loadcheck {
>   my ($self, $transaction) = @_;
> 
>   my $hiload = 0;
> 
>   my $cmd = $self->{_args}->{uptime};
>   #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+)/) {
>       $hiload = $1;
>   }
> 
>   if ($hiload > $self->{_args}->{max_load}) {
>       $self->log(LOGERROR, "local load too high: $hiload");
>       return DENYSOFT;
>   }
> 
>   return (DECLINED, "continuing with load: $hiload");
> }

Reply via email to