2006. 8. 1. 14:11
MRTG For Postfix
2006. 8. 1. 14:11 in Operation System/FreeBSD
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 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:
You need to download the following three scripts:
update-mailstats.pl
mailstats.pl
mrtg-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:
following line in mrtg-mailstats.pl:
$mailstats = "/usr/local/bin/mailstats.pl" ;
HOWTO1. 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 itever gets killed.)
this updates a file called /tmp/stats.db (adjust to suit your needs)
with the inbound and outbound mail stats.
with the inbound and outbound mail stats.
the logic of this script is extremely simple (and probably far from
perfect):
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.
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.
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.
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
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:
3. add lines like the following to your mrtg.cfg:
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: Incoming:
?LegendO?postfix: Outgoing:
#---------------------------------------------------------------#
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
위와 같이 하면 성공.
update-mailstats.pl & 을 실행했을때, 아래와 같은 에러 메세지를 출력한다면,
Can't locate File/Tail.pm in @INC.....
Can't locate File/Tail.pm in @INC.....
# wget http://search.cpan.org/CPAN/authors/id/M/MG/MGRABNAR/File-Tail-0.98.tar.gz# tar xvfz File-Tail-0.98.tar.gz# cd File-Tail-0.98# perl Makefile.PL# make# make test# make install하여, File-Tail을 설치를 해준다...