views:

2454

answers:

2

What is a good command to monitor a Postfix installation on a linux server? It should be one command that can be run from a command prompt in an SSH session and returns information about whether the postfix process is active and the size of the relevant mail queues.

+2  A: 

You can use the command line programs that come with Postfix:

  • mailq : shows which queues have mail being 'processed'
  • postqueue -p : is what mailq actually references
  • postqueue -f : flushes all queued mail, immediately trying to get it delivered
  • ps aux : shows running processes on the server, look for things like:
    • smtpd
    • proxymap
    • anvil
    • trivial-rewrite
    • qmgr
    • pickup
    • showq

What you find with the ps command will vary depending on how you set things up.

Redbeard 0x0A
+1  A: 

In order of preference:

The best way is to send heartbeat messages through the mail server and monitor their arrival at the destination.

Use mailq and qshape (shipped with recent postfix distributions) to monitor queues.

You can check that smtpd is listening and returning a banner using netcat (options to netcat vary by OS; these are for linux):

nc -w 1 localhost 25 </dev/null

The following will report the number of processes for each postfix daemon, grouped by master (multiple masters if you have multiple postfix instances).

ps -e -o pid,ppid,fname | perl -lane '
    if ($F[1] != 1) {
        ++$c{$F[1]}->{$F[2]};
    } elsif ($F[2] eq "master") {
        push(@masters, $F[0]);
    }
    END {
        foreach $master (@masters) {
            print "=== master: $master ===";
            foreach $agent (keys %{$c{$master}}) {
                printf "\t%-5d %s\n", $c{$master}->{$agent}, $agent;
            }
        }
   }
'
robc