From 1f036fee90297adc07b9f615bf739966365ab0ba Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Wed, 8 Jun 2005 22:24:00 +0000 Subject: [PATCH] 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 --- lib/Qpsmtpd/ConfigServer.pm | 12 ++++++------ lib/Qpsmtpd/Stats.pm | 35 ----------------------------------- plugins/stats | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 44 deletions(-) delete mode 100644 lib/Qpsmtpd/Stats.pm diff --git a/lib/Qpsmtpd/ConfigServer.pm b/lib/Qpsmtpd/ConfigServer.pm index fd2c8a7..7a92d64 100644 --- a/lib/Qpsmtpd/ConfigServer.pm +++ b/lib/Qpsmtpd/ConfigServer.pm @@ -155,13 +155,13 @@ sub cmd_status { 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 - my $uptime = Qpsmtpd::Stats->uptime; - my $recvd = Qpsmtpd::Stats->mails_received; - my $reject = Qpsmtpd::Stats->mails_rejected; - my $soft = Qpsmtpd::Stats->mails_tempfailed; - my $rate = Qpsmtpd::Stats->mails_per_sec; + my $uptime = Qpsmtpd::Plugin::stats->uptime; + my $recvd = Qpsmtpd::Plugin::stats->mails_received; + my $reject = Qpsmtpd::Plugin::stats->mails_rejected; + my $soft = Qpsmtpd::Plugin::stats->mails_tempfailed; + my $rate = Qpsmtpd::Plugin::stats->mails_per_sec; $output .= sprintf(" Uptime: %0.2f sec\n". " Mails Received: % 10d\n". " 5xx: % 10d\n". diff --git a/lib/Qpsmtpd/Stats.pm b/lib/Qpsmtpd/Stats.pm deleted file mode 100644 index a858b9f..0000000 --- a/lib/Qpsmtpd/Stats.pm +++ /dev/null @@ -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; \ No newline at end of file diff --git a/plugins/stats b/plugins/stats index 200cac9..1a2e1b5 100644 --- a/plugins/stats +++ b/plugins/stats @@ -1,6 +1,12 @@ #!/usr/bin/perl -w 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 { my ($self) = @_; @@ -13,10 +19,10 @@ sub increment_deny { my ($self, $tran, $plugin, $level) = @_; if ($level == DENY or $level == DENY_DISCONNECT) { - $Qpsmtpd::Stats::MAILS_REJECTED++; + $MAILS_REJECTED++; } elsif ($level == DENYSOFT or $level == DENYSOFT_DISCONNECT) { - $Qpsmtpd::Stats::MAILS_TEMPFAIL++; + $MAILS_TEMPFAIL++; } return DECLINED; @@ -25,7 +31,29 @@ sub increment_deny { sub increment_mails { my $self = shift; - $Qpsmtpd::Stats::MAILS_RECEIVED++; + $MAILS_RECEIVED++; 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()); +} + +