Move the stats code purely into the plugin so that this can be extended
easier. git-svn-id: https://svn.perl.org/qpsmtpd/branches/high_perf@429 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
42e49d493a
commit
1f036fee90
@ -155,13 +155,13 @@ sub cmd_status {
|
|||||||
|
|
||||||
my $output = "Current Status as of " . gmtime() . " GMT\n\n";
|
my $output = "Current Status as of " . gmtime() . " GMT\n\n";
|
||||||
|
|
||||||
if ($INC{'Qpsmtpd/Stats.pm'}) {
|
if (defined &Qpsmtpd::Plugin::stats::register) {
|
||||||
# Stats plugin is loaded
|
# Stats plugin is loaded
|
||||||
my $uptime = Qpsmtpd::Stats->uptime;
|
my $uptime = Qpsmtpd::Plugin::stats->uptime;
|
||||||
my $recvd = Qpsmtpd::Stats->mails_received;
|
my $recvd = Qpsmtpd::Plugin::stats->mails_received;
|
||||||
my $reject = Qpsmtpd::Stats->mails_rejected;
|
my $reject = Qpsmtpd::Plugin::stats->mails_rejected;
|
||||||
my $soft = Qpsmtpd::Stats->mails_tempfailed;
|
my $soft = Qpsmtpd::Plugin::stats->mails_tempfailed;
|
||||||
my $rate = Qpsmtpd::Stats->mails_per_sec;
|
my $rate = Qpsmtpd::Plugin::stats->mails_per_sec;
|
||||||
$output .= sprintf(" Uptime: %0.2f sec\n".
|
$output .= sprintf(" Uptime: %0.2f sec\n".
|
||||||
" Mails Received: % 10d\n".
|
" Mails Received: % 10d\n".
|
||||||
" 5xx: % 10d\n".
|
" 5xx: % 10d\n".
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
# $Id$
|
|
||||||
|
|
||||||
package Qpsmtpd::Stats;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Qpsmtpd;
|
|
||||||
use Qpsmtpd::Constants;
|
|
||||||
use Time::HiRes qw(time);
|
|
||||||
|
|
||||||
my $START_TIME = time;
|
|
||||||
our $MAILS_RECEIVED = 0;
|
|
||||||
our $MAILS_REJECTED = 0;
|
|
||||||
our $MAILS_TEMPFAIL = 0;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
return ($MAILS_RECEIVED / uptime());
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
@ -1,6 +1,12 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
use Qpsmtpd::Stats;
|
use Qpsmtpd::Stats;
|
||||||
|
use Time::HiRes qw(time);
|
||||||
|
|
||||||
|
my $START_TIME = time;
|
||||||
|
our $MAILS_RECEIVED = 0;
|
||||||
|
our $MAILS_REJECTED = 0;
|
||||||
|
our $MAILS_TEMPFAIL = 0;
|
||||||
|
|
||||||
sub register {
|
sub register {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
@ -13,10 +19,10 @@ sub increment_deny {
|
|||||||
my ($self, $tran, $plugin, $level) = @_;
|
my ($self, $tran, $plugin, $level) = @_;
|
||||||
|
|
||||||
if ($level == DENY or $level == DENY_DISCONNECT) {
|
if ($level == DENY or $level == DENY_DISCONNECT) {
|
||||||
$Qpsmtpd::Stats::MAILS_REJECTED++;
|
$MAILS_REJECTED++;
|
||||||
}
|
}
|
||||||
elsif ($level == DENYSOFT or $level == DENYSOFT_DISCONNECT) {
|
elsif ($level == DENYSOFT or $level == DENYSOFT_DISCONNECT) {
|
||||||
$Qpsmtpd::Stats::MAILS_TEMPFAIL++;
|
$MAILS_TEMPFAIL++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DECLINED;
|
return DECLINED;
|
||||||
@ -25,7 +31,29 @@ sub increment_deny {
|
|||||||
sub increment_mails {
|
sub increment_mails {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$Qpsmtpd::Stats::MAILS_RECEIVED++;
|
$MAILS_RECEIVED++;
|
||||||
|
|
||||||
return DECLINED;
|
return DECLINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return ($MAILS_RECEIVED / uptime());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user