0

Does anyone have a script that can output the number of mails sent in the last hour, i.e. sendmail outgoing throughput. It should be possible to determine by analysing the mail log (/var/log/maillog)?

Perhaps there is some FOSS to help?

Using mailstats (/usr/sbin/mailstats) doesn't seem to be much use as it only gives stats from when the mail server was first turned on, not in the last hour. Perhaps I'm wrong?

2
  • Are you looking for a stats/graphing program, or a one-off command line to get the number of mails sent over the last hour? Sep 28, 2009 at 16:38
  • Ideally a one-off command line entry to get the number of mails sent over the last hour.
    – Tom
    Sep 29, 2009 at 8:22

3 Answers 3

1

You're wrong about mailstats I think. If you use the "-p" flag it will reset the stats so you can run it hourly from cron like this:

/usr/sbin/mailstats -p

...and start fresh stats for the next hour. Hope that helps.

0
0

I'm not very familiar with sendmail, as I prefer postfix, but you can use either pflogsum for daily stats or grep'ing thru /var/log/maillog for ad hoc type questions. Examples:

grep 'Sep 28 09:' /var/log/maillog | grep 250 | wc -l

should get you the number of succesfully delivered emails from 09:00 to 09:59 on Sept 28th.

1
  • Are you saying that pflogsumm works with sendmail?
    – markus
    Oct 4, 2013 at 15:42
0

For Info - this is the script I ended up with (set to run via cron each hour):

#!/usr/bin/php
<?php

// Get time in sendmail format for last hour.
$dateMonth = date("M", strtotime("-1 hour"));
$dateDay   = date("j", strtotime("-1 hour"));
if ($dateDay < 10)
 $dateDay = " $dateDay";
$dateHour  = date("H", strtotime("-1 hour"));

$numSent = shell_exec("grep '{$dateMonth} {$dateDay} {$dateHour}:' /var/log/maillog | grep 'Message accepted for delivery' | wc -l");

// Log value
$logFile = "whereEverYouWant.log";
if(($fh = fopen($logFile,'a')) === FALSE)
 die("Failed to open \"$logFile\" for appending!\n");
fwrite($fh, date('Y-m-d, H:i:s') . ", $numSent");
fclose($fh);
?>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .