Re: [Exim] [Wishlist] Have exim log the time on queue

Pàgina inicial
Delete this message
Reply to this message
Autor: Tony Finch
Data:  
A: exim-users
Assumpte: Re: [Exim] [Wishlist] Have exim log the time on queue
Nigel Metheringham <Nigel.Metheringham@???> wrote:
>On Wed, 2003-03-05 at 14:09, Marc Haber wrote:
>>
>> I would like to have an option to allow exim to log the time a message
>> has spent on the local queue in the delivery log entry. That way, it
>> would be very easy to deliver statistics of "average time on queue"
>> for each message.
>
>You can decode the exim message id (queue file name) to extract the time
>a message was received, making it possible to extract the time on queue
>from just the information in the delivered log line.


#!/usr/bin/perl -w
#
# Work out message handling times from Exim logs.
# Note this assumes UTC log timestamps.
# This should be built-in to Exim :-)

use strict;

sub b62toi ($) {
    my $s = shift;
    my $i = 0;
    for (;;) {
        if ($s =~ s/^([0-9])//) {
            $i = $i*62 + ord($1) - 48;
        } elsif ($s =~ s/^([A-Z])//) {
            $i = $i*62 + ord($1) - 55;
        } elsif ($s =~ s/^([a-z])//) {
            $i = $i*62 + ord($1) - 61;
        } elsif ($s =~ /^$/) {
            return $i;
        } else {
            die "Bad base62 character";
        }
    }
}


sub unixtime ($$$$$$) {
    my ($y,$m,$d,$H,$M,$S) = @_;
    use integer;
    $y -= $m < 3;
    $m += $m < 3 ? 10 : -2;
    my $t = $y/400 - $y/100 + $y/4 + $y*365
          + $m*367/12 + $d - 719499;
    $t = $t * 86400
       + $H * 3600
       + $M * 60
       + $S;
    return $t;
}


while (<>) {
    if (m{^(\d\d\d\d)-(\d\d)-(\d\d)\s(\d\d):(\d\d):(\d\d)\s
               (\S\S\S\S\S\S)-(\S\S\S\S\S\S)-(\S\S)\s
               ([-=*]>|[*=][*=]|Completed)}x) {
        my $now = unixtime $1, $2, $3, $4, $5, $6;
        my $then = b62toi $7;
        my $time = $now - $then;
        s/$/ t=$time/;
    }
    print;
}


Tony.
--
f.a.n.finch <dot@???> http://dotat.at/
ARDNAMURCHAN POINT TO CAPE WRATH INCLUDING THE OUTER HEBRIDES: SOUTH OR
SOUTHWEST 6 TO GALE 8 EASING 4 OR 5 DURING THE EVENING. SHOWER. GOOD. ROUGH OR
VERY ROUGH, BUT SLIGHT TO MODERATE IN SHELTER.