From 95102e68c5198f1421c36e73b0b688ae34a01739 Mon Sep 17 00:00:00 2001 From: Richard Siddall Date: Thu, 13 Feb 2014 21:42:56 -0500 Subject: [PATCH] Added Peter Eisch's load checking plugin, see: http://www.nntp.perl.org/group/perl.qpsmtpd/2006/01/msg4422.html, and Steve Kemp's alternative at: http://www.nntp.perl.org/group/perl.qpsmtpd/2008/03/msg7814.html --- plugins/loadcheck | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 plugins/loadcheck diff --git a/plugins/loadcheck b/plugins/loadcheck new file mode 100644 index 0000000..dd0493f --- /dev/null +++ b/plugins/loadcheck @@ -0,0 +1,74 @@ +#!/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 . + +=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"); +} +