Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  Dave Drager Sep 28 '09 at 16:38
    
Ideally a one-off command line entry to get the number of mails sent over the last hour. –  Tom Sep 29 '09 at 8:22
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks for the info –  Tom Oct 9 '10 at 11:56
add comment

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.

share|improve this answer
    
Are you saying that pflogsumm works with sendmail? –  markus Oct 4 '13 at 15:42
add comment

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);
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.