# Postfix stats?

## zgredek

Is there any program that creates graphs, etc. based on the number of delivered/rejected messages + maybe a total number of received/sent mails for each user?

Thx

----------

## dashnu

awstats works well for me. 

It will tell you things like so..

Mails successfully sent	 

Mails failed/refused

Monthly / Daily / Weekly / Hourly Stats

Visitors domains/countries

Hosts

Sender EMail (Mails sent total size average size)

Receiver EMail (Mails received total size average size)

And some other stuff.

----------

## splooge

pflogsumm works well also, but it's not graphical, it's text based.  It's a good thing to run nightly via cron and e-mail output to whomever you wish it to go to.

----------

## hanj

Cacti can graph postfix info...

http://forums.cacti.net/about7314.html&highlight=postfix

net-analyzer/cacti-0.8.6g

net-analyzer/cacti-cactid-0.8.6e

HTH

hanji

----------

## zgredek

cacti is not working properly, but it's the best of those i've seen... There're some problem with the graphs not being displayed or some data not showing up, strange...  Additionally, postfix supoprt? Anyone? The link on: http://forums.cacti.net/about7314.html&highlight=postfix seems to be broken...

----------

## hanj

Hello

Give this a try...

http://forums.cacti.net/about1571-0-asc-15.html

[mailgraph-jjp.zip] is the file you want.

I got it working on my system. You need to modify it to work in linux enviro (basically changing the paths). It was originally configured to work in FreeBSD. Just follow the instructions in the INSTALL document.

I'm seeing a nice graph of:

Received

Send

Reject

Bounce

Spam

Virus

Here is my /etc/conf.d/mailgraph

```
MG_POSTFIX_LOG="/var/log/mail.log"

# Specify any extra options here.

# If MG_POSTFIX_LOG is in metalog format, add "-t metalog" to MG_OPTS

MG_OPTS=" --ignore-localhost --ignore-host=spamfilter

```

HTH

hanji

----------

## hanj

Hmmmm

I'm having some problems with the graph. I'll let you know when I have a fix.

hanji

----------

## hanj

Okay. Got things working. A special thanks goes to Volumen1 for helping.. he's a madman.

Here is quick procedure to get Postfix graphing working in cacti. This quick howto assumes you already have postfix, snmp and cacti working.

```
emerge -v mailgraph
```

Grab this file. It's a rework on mailgraph.

http://forums.cacti.net/download.php?id=1925

Information can be found here:

http://forums.cacti.net/about1571-0-asc-15.html

```
cd /usr/local/src

cp /where/you/have/mailgraph-jjp.zip .

unzip mailgraph-jjp.zip

cd mailgraph-jjp
```

Need to copy over existing mailgraph script (you may want to back up the original)

```
cp mailgraph.pl /usr/bin/mailgraph

vi /usr/bin/mailgraph

```

Comment out these two lines

```
line 690 #return 1 if $m == $this_minute;

line 691 #return 0 if $m < $this_minute;

```

Set this value (or where ever you have mail logging to) in /etc/conf.d/mailgraph

```
MG_POSTFIX_LOG="/var/log/mail.log"
```

Now copy over the postfixstats.sh script

```
cp /usr/local/src/mailgraph-jjp/postfixstats.sh /usr/local/bin/.

chmod 755 /usr/local/bin/postfixstats.sh

vi /usr/local/bin/postfixstats.sh
```

Change

```
#!/usr/local/bin/bash
```

to

```

#!/bin/bash
```

Copy over the postfixcheck.pl to cacti scripts directory

```
cp /usr/local/src/mailgraph-jjp/postfixcheck.pl /path/to/cacti/scripts/.

chmod 755 /path/to/cacti/scripts/postfixcheck.pl

vi /path/to/cacti/scripts/postfixcheck.pl
```

Add your snmp community string in the perl file

Create the counter files in /var/tmp

```
touch /var/tmp/mailreceived

touch /var/tmp/mailsent

touch /var/tmp/mailrejected

touch /var/tmp/mailbounced

touch /var/tmp/mailspam

touch /var/tmp/mailvirus 
```

Edit /etc/snmp/snmpd.conf

Add this line to the file and restart snmpd

```
exec mailcount /usr/local/bin/postfixstats.sh
```

```
/etc/init.d/snmpd restart
```

Add mailgraph to runlevel and start it up.

```
rc-update add mailgraph default

/etc/init.d/mailgraph start
```

If you have any problems check /var/log/mailgraph.log

At this point you should be seeing counters increment in the /var/tmp files when mails come and go. I would recommend doing the following tests:

```
/usr/local/bin/postfixstats.sh

/path/to/cacti/scripts/postfixcheck.pl localhost
```

Make sure you see counters increment.. and then get reset to 0. If that is happening.. you're looking good.

Next add the cacti_graph_template_postfix_processing.xml to cacti graph templates and add the postfix graph. Make sure you set it to localhost.

This is working on my system with the following relevant packages/versions

net-analyzer/net-snmp-5.2.1.2-r1

net-analyzer/cacti-0.8.6g

mail-mta/postfix-2.2.5

net-mail/mailgraph-1.11-r1 (this is overwritten w/diff mailgraph)

HTH

hanji

----------

## Dwalin

 *hanj wrote:*   

> ...
> 
> ```
> exec mailcount /usr/local/bin/postfixstats.sh
> ```
> ...

 

Hi hanj,

I tried to follow your small how-to, but I could not find "mailcount". Is it a little script? where could I find it?

Thanks for your help

Thomas

----------

## Janne Pikkarainen

isoqlog is also very useful.

----------

## hanj

 *Dwalin wrote:*   

>  *hanj wrote:*   ...
> 
> ```
> exec mailcount /usr/local/bin/postfixstats.sh
> ```
> ...

 

Hello

It's been awhile.. so trying to wipe the dust off. I believe, and if I'm wrong.. someone please correct me, that the 'mailcount' is like the return variable name. So the /usr/local/bin/postfixstats.sh executes and counts the mails, and returns the value to the mailcount variable. That variable:value is used by cacti.

/usr/local/bin/pastfixstats has the following:

```
#!/bin/bash

for i in sent received rejected bounced spam virus;

do

  c=$(/bin/cat /var/tmp/mail$i)

  result="${result} ${i}:${c}"

  echo 0 > /var/tmp/mail$i

done

echo $result
```

So it returns the $result value to the mailcount variable. /cacti/scripts/postfixcheck.pl picks it up.

Hope this helps

hanji

----------

## Dwalin

ah ok, now I understand, thanks for the quick help

----------

## pydubreucq

Hi,

Excuse me I'm French and I don't speak english very well.

I use "Postfix processing" on cacti and I have a problem.

My graph is not complet.

I have the good number of received mail, sent mail... I hope  :Wink: 

You could see the result of my graph here :

http://demo-ez.telmedia.net/cacti.jpg

You'll see the good count of received message on current message but not on graph  :Sad: 

If you have an idea ?

I will very happy

Thanks for all  :Wink: 

----------

