Re: [Exim] wishlist: delay and xdelay in the log

Top Page
Delete this message
Reply to this message
Author: Tony Finch
Date:  
To: Thomas Egrelius
CC: exim-users
Subject: Re: [Exim] wishlist: delay and xdelay in the log
On Thu, 1 Apr 2004, Thomas Egrelius wrote:
>
> Would it be possible to have the time the message have been on the queue
> added to the delivery log entry, like sendmails delay= and xdelay=? This
> would make it easy to spot and track email delays without having to do
> eximstats on the large logfiles or track delays from email headers.


Note that message IDs include a base-62-encoded timestamp which marks the
time that Exim received the DATA command. This may be some time before the
<= log line for the message owing to slow transmission times (e.g. from
dial-up machines).

#!/usr/bin/perl -w
#
# Work out message handling times from Exim logs.
# Note this assumes UTC.
#
# $Cambridge: hermes/src/admin/logtime.pl,v 1.1 2003/03/05 15:25:39 fanf2 Exp $

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;
}


exit;

--
Tony Finch <dot@???> http://dotat.at/