Cory Coager wrote:
Ralf Hildebrandt said the following on 01/08/2009 08:39 AM:
* Cory Coager <ccoa...@davisvision.com>:
I'm attempting to generate some rrd graphs to track MTA connections for
postfix.  With sendmail it was possible to do this by greping the ps
list for the number of sendmail processes.  How would I accomplish this
on postfix?

grep for the smtp processes (not smtpd)
(or vice versa)

The number of smtp processes never changes so this won't work.


~Cory Coager

Postfix keeps idle processes around for $max_idle (default 100s), so the process count is only an approximation of the number of connections. Idle processes are reused $max_use (default 100) times before they are retired. The number of processes will change with the number of connections until the maximum number of configured connections is reached. I suspect this is similar to what you get when counting "sendmail" processes.

To get an accurate connection count, you will need to parse "netstat" or "lsof" output to count established connections. Even this may give an inaccurate number if there are more connections than available smtpd processes.

I use this perl "one liner" on FreeBSD, you may need to adjust it for another OS.

netstat -an 2>/dev/null | perl -lne '
    $in = "0" if $in == undef;
    $out = "0" if $out == undef;
    ++$in if (/ESTABLISHED/
&& /(?:^|\s)\d+\.\d+\.\d+\.\d+[.:](\d+)\s+\d+\.\d+\.\d+\.\d+[.:]\d+/
        && $1 eq "25");
    ++$out if (/ESTABLISHED/
&& /(?:^|\s)\d+\.\d+\.\d+\.\d+[.:]\d+\s+\d+\.\d+\.\d+\.\d+[.:](\d+)/
             && $1 eq "25");
END {print $ARGV[0], "Port 25 status: ", $in, " Established incoming, ", $out, " Established outgoing"};
'


--
Noel Jones

Reply via email to