2005-04-28 23:38:43 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
2005-06-09 00:24:00 +02:00
|
|
|
use Time::HiRes qw(time);
|
|
|
|
|
|
|
|
my $START_TIME = time;
|
|
|
|
our $MAILS_RECEIVED = 0;
|
|
|
|
our $MAILS_REJECTED = 0;
|
|
|
|
our $MAILS_TEMPFAIL = 0;
|
2005-04-28 23:38:43 +02:00
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->register_hook('deny', 'increment_deny');
|
|
|
|
$self->register_hook('queue', 'increment_mails');
|
|
|
|
}
|
|
|
|
|
2005-06-09 00:25:28 +02:00
|
|
|
sub get_stats {
|
2005-06-15 22:34:34 +02:00
|
|
|
my $class = shift;
|
|
|
|
my $uptime = $class->uptime;
|
|
|
|
my $recvd = $class->mails_received;
|
|
|
|
my $reject = $class->mails_rejected;
|
|
|
|
my $soft = $class->mails_tempfailed;
|
|
|
|
my $rate = $class->mails_per_sec;
|
2005-06-09 00:25:28 +02:00
|
|
|
return sprintf(" Uptime: %0.2f sec\n".
|
|
|
|
" Mails Received: % 10d\n".
|
|
|
|
" 5xx: % 10d\n".
|
|
|
|
" 4xx: % 10d\n".
|
|
|
|
"Mails per second: %0.2f\n",
|
|
|
|
$uptime, $recvd, $reject, $soft, $rate);
|
|
|
|
}
|
|
|
|
|
2005-04-28 23:38:43 +02:00
|
|
|
sub increment_deny {
|
2005-05-09 15:41:10 +02:00
|
|
|
my ($self, $tran, $plugin, $level) = @_;
|
2005-04-28 23:38:43 +02:00
|
|
|
|
|
|
|
if ($level == DENY or $level == DENY_DISCONNECT) {
|
2005-06-09 00:24:00 +02:00
|
|
|
$MAILS_REJECTED++;
|
2005-04-28 23:38:43 +02:00
|
|
|
}
|
|
|
|
elsif ($level == DENYSOFT or $level == DENYSOFT_DISCONNECT) {
|
2005-06-09 00:24:00 +02:00
|
|
|
$MAILS_TEMPFAIL++;
|
2005-04-28 23:38:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return DECLINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub increment_mails {
|
|
|
|
my $self = shift;
|
|
|
|
|
2005-06-09 00:24:00 +02:00
|
|
|
$MAILS_RECEIVED++;
|
2005-04-28 23:38:43 +02:00
|
|
|
|
|
|
|
return DECLINED;
|
2005-05-09 15:41:10 +02:00
|
|
|
}
|
2005-06-09 00:24:00 +02:00
|
|
|
|
|
|
|
sub uptime {
|
|
|
|
return (time() - $START_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mails_received {
|
|
|
|
return $MAILS_RECEIVED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mails_rejected {
|
|
|
|
return $MAILS_REJECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mails_tempfailed {
|
|
|
|
return $MAILS_TEMPFAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mails_per_sec {
|
2005-06-15 22:34:34 +02:00
|
|
|
my $class = shift;
|
|
|
|
return ($MAILS_RECEIVED / $class->uptime());
|
2005-06-09 00:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|