Peter Gradwell writes:
> At 2:15 pm +0000 12/2/99,the wonderful Russell Nelson wrote:
> >I have MRTG reporting on the number of deliveries per five minute
> >period. http://www.crynwr.com/mrtg/messages.html. I'm running
> >qmail-analog every five minutes, on the previous integral five minute
> >slice of the data. Right now, I'm recording the number of
> >deliveries. I could record anything else, though. Candidates?
>
> wow!
>
> I'd love to know how you did this :-)
>
> especially, how you got the qmail analog detail into a form for mtrg to plot it.
By parsing the output of zoverall. (In other words, pure laziness).
Strictly speaking, I ought to do the summations myself, I just didn't
(and don't) have the time to do it right.
> also, I think it would be really useful to know the amount of mail
> data transfered per user in graph form! That comes out from the
> qmailanalog report zsuids, I think.
Hmmm.... I don't think mrtg would be well-suited for plotting that information.
Here's the relevant section from my mrtg.cfg:
Title[messages]: Crynwr Software
MaxBytes[messages]: 100
AbsMax[messages]: 10000
Options[messages]: gauge
Target[messages]: `/usr/local/bin/qmail-mrtg /var/log/qmail`
PageTop[messages]: <H1>Crynwr Software</H1>
<P>Number of messages
YLegend[messages]: Messages
Legend1[messages]: Total messages
LegendI[messages]: Deliveries:
LegendO[messages]: Attempts:
WithPeak[messages]: ymwd
And qmail-mrtg follows:
#!/usr/bin/perl
# analyze the last five minutes of a cyclog-format qmail log.
#----------- Configuration -------------
$logperiod = 5*60; # change if logging other than 5 mins.
$holdingfile = "/usr/local/lib/pending.mrtg"; # rewritten every $logperiod.
$qa = "/usr/local/qmailanalog/bin"; # location of qmailanalog bindir.
$qmail_log_dir = shift;
# compute the start and stop periods. We do the precise five minute
# period (e.g. 05:00 -> 09:59) prior to this moment, to ensure that
# every five minute period is covered.
$stop = $^T;
$seconds = $logperiod - $stop % $logperiod;
$seconds = 0 if ($seconds == $logperiod);
$stop -= $seconds;
$start = $stop - $logperiod;
# get the last two files. We process both of them so we don't have to
# deal with cyclog having switched just before, during or after we started.
# Ensure that the earlier of the two logs was started before $start.
opendir(DIR, $qmail_log_dir) or die;
@_ = sort readdir(DIR);
@ARGV = splice(@_, -2, 2);
$earlier = @ARGV[0];
$earlier =~ s/^\@//;
die if $earlier > $start;
map($_ = "$qmail_log_dir/$_", @ARGV);
# process the two files, and run them through matchup.
open(P, "<$holdingfile") or die;
open(QA, "|$qa/matchup >/tmp/out.$$ 5>$holdingfile") or die;
while(<P>) { print QA; }
close(P);
while(<>) {
split;
next if ($_[0] < $start || $_[0] >= $stop);
print QA;
}
# analyze the last five minutes.
open(REP, "$qa/zoverall </tmp/out.$$|") or die;
while(<REP>) {
if (/^Completed messages: (\d+)/) {
print "$1\n";
if (!$1) {
print "0\n";
exit;
}
}
print "$1\n" if /^Recipients for completed messages: (\d+)/;
}
close(REP);
# cleanup.
unlink("/tmp/out.$$");
--
-russ nelson <[EMAIL PROTECTED]> http://crynwr.com/~nelson
Crynwr supports Open Source(tm) Software| PGPok | There is good evidence
521 Pleasant Valley Rd. | +1 315 268 1925 voice | that freedom is the
Potsdam, NY 13676-3213 | +1 315 268 9201 FAX | cause of world peace.