NOTE:This hack needs the File::Tail perl module by Matija Grabnar.
Download it from CPAN and install it first.
See 'man CPAN' for more info about installing CPAN modules.

DOWNLOAD
--------
You need to download the following three scripts:

update-mailstats.pl
mailstats.pl
mrtg-mailstats.pl

save them all in /usr/local/bin and make them executable.

if you save them in a different directory then you will have to edit the
following line in mrtg-mailstats.pl:

	$mailstats = "/usr/local/bin/mailstats.pl" ;

HOWTO
-----

1. run the update-mailstats.pl program in the background like so:

	update-mailstats.pl &

(you probably want to write a wrapper script to restart it in case it
ever gets killed.)

this updates a file called /tmp/stats.db (adjust to suit your needs)
with the inbound and outbound mail stats.

the logic of this script is extremely simple (and probably far from
perfect):

if the line contains "status=sent" then figure out the transport from
the "relay=" part of the line. if relay= contains "[" then assume it's
an IP address, and transport is smtp. otherwise, transport is whatever
the "relay=" bit says.

if line contains "smtpd.*client=" then we've received a message via
smtp. if line contains "pickup.*(sender|uid)=" then we've received a
message from a local user.

very simple, mostly works. i'm sure there are cases which it doesn't
catch.  if you can improve it, let me know.

to tell the truth, it doesn't matter if it's 100% accurate or not.
the point is to give a pretty graph of some meaningless numbers to
management types. they love it :)



2. if you want to see the raw data, use the mailstats.pl script:
	
	$ mailstats.pl
	RECEIVED:local 162
	RECEIVED:smtp 4253
	SENT:local 4101
	SENT:smtp 5118



3. add lines like the following to your mrtg.cfg:

	
	#---------------------------------------------------------------#
	# MRTG mail cfg:  Postfix mailstats plotting with MRTG          #
	#---------------------------------------------------------------#
	Target[postfix]: `/usr/local/bin/mrtg-mailstats.pl`
	Options[postfix]: gauge, growright
	Title[postfix]: Postfix Statistics
	PageTop[postfix]: <H1>Postfix Statistics</H1>
	WithPeak[postfix]: dwmy
	YLegend[postfix]: No. of messages
	ShortLegend[postfix]: messages
	LegendI[postfix]: &nbsp;Incoming:
	LegendO[postfix]: &nbsp;Outgoing:
	#---------------------------------------------------------------#

this runs the mrtg-mailstats.pl programs which totals the RECEIVED and
SENT lines output by mailstats.pl and then outputs it in a form
suitable for MRTG. it keeps the previous RECEIVED and SENT counts in
/tmp/mailstats.old