Ad Widget

Collapse

Sendmail queue size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rts
    Member
    • May 2007
    • 54

    #1

    Sendmail queue size

    Hi,

    Does anyone have a template for monitoring Sendmail's status? I just got caught out when I found a server with 22,000 emails in the /var/log/mqueue directory, and I wish Zabbix had told me!

    Many thanks,

    rts
  • bbrendon
    Senior Member
    • Sep 2005
    • 870

    #2
    If there is, it'll be in the wiki.

    No template here, but I can think of many commands and items to use
    mailq|wc -l
    ls -1 /var/log/mqueue|wc -l
    ...
    Unofficial Zabbix Expert
    Blog, Corporate Site

    Comment

    • rts
      Member
      • May 2007
      • 54

      #3
      Yeah - I wasn't sure if there was anything more intelligent (eg number of messages that have been unable to be delivered for > 1hr or similar).

      Anyway, thanks for your suggestions.


      rts

      Comment

      • txalin
        Member
        • Jan 2008
        • 31

        #4
        Create a user parameter an play with mailq command, it displays the sendmail queue and so...

        Comment

        • johnnyirons
          Junior Member
          • Dec 2007
          • 16

          #5
          doing this by the mailq command is expensive, better using the filesystem.
          you need to watch only for qf* (NOT Qf!) files inside the spool dir, so much like this:
          Code:
          # find /var/spool/mqueue -type f -name qf\* -print|wc -l|tr -d ' '
          this actually works. you need to strip spaces that wc produces.

          i'd rather parametrize the spool dir as we have multiple queues.


          alternatively, yo can invoke a script like this: if you invoke that with -q, it just prints out the # mails in the queue (useful via the UserParameter in the agent), or without arguments it produces a lot of status info on the queue.
          you'll need the two modules at the top.
          enjoy.
          Code:
          #!/usr/bin/perl
          # this script scans the queue directory
          # for metrics on its status.
          # Giovanni Ferri <[email protected]> 2009
          
          use File::Find;
          use Getopt::Long;
          
          
          $mqueue_directory = "/var/spool/mqueue";
          # default values
          my $sortmethod="domain";
          my $limit=10;
          
          &read_options;
          
          # Recursively find all files and directories in $mqueue_directory
          find(\&Wanted, $mqueue_directory);
          
          sub Wanted
          {
            # Is this a qf* file?
            if ( /^qf/ ) {
               open (QF_FILE, $_);
               while(<QF_FILE>) {
                  # The line beginning with rRFC822; contains the envelope recipient
                  if ( /^rRFC822;\s(.*)@(.*)$/ ) {
                  	#print "$_ $1\@$2\n";
                     if ( $sortmethod eq 'domain' ) { $recvtoken{"$2"} += 1; } else { $recvtoken{"$1\@$2"} += 1; }
                     #last;
                  # line starting with S is the sender
                  } elsif ( /^S<(.*)@(.*)>$/ ) {
                     if ( $sortmethod eq 'domain' ) { $sendertoken{"$2"} += 1; } else { $sendertoken{"$1\@$2"} += 1; }
                     #last;
                  }
          
               }
            }
          }
          
          # Subroutine to sort hash by ascending value
          sub hashValueAscendingRecvtoken {
            $recvtoken{$a} <=> $recvtoken{$b};
          }
          sub hashValueAscendingSendertoken {
            $sendertoken{$a} <=> $sendertoken{$b};
          }
          
          
          
          sub read_options {
                 GetOptions("sort|s=s"  => \$sortmethod,
                            "limit|l=i" => \$limit,
                            "domain|d"  => sub { $sortmethod='domain' },
                            "user|u"    => sub { $sortmethod='user' },
                            "quiet|q"   => \$quiet
                         );
          
                 if ( $sortmethod != "domain" || $sortmethod != "user" ) {
                 	print "Sort can be: user domain(default) .\n";
                 	exit 1;	
                 }
          }
          
          	
          ##---------
          
          # Print sorted results
          print "Top $sortmethod by recipient:\n"  unless ($quiet);
          $c=0;
          foreach $key (reverse sort hashValueAscendingRecvtoken (keys(%recvtoken))) {
            $c++;
            $total += $recvtoken{$key};
            if ($c <= $limit) {
          		   print "$recvtoken{$key}\t$key\n"  unless ($quiet);
            }
          }
          print "Top $sortmethod by sender:\n"  unless ($quiet);
          unless ($quiet) {
          	$c=0;
          	foreach $key (reverse sort hashValueAscendingSendertoken (keys(%sendertoken))) {
          	   $c++;
          	   #$total += $sendertoken{$key};
          	   if ($c <= $limit) {
          			   print "$sendertoken{$key}\t$key\n";
          	   }
          	}
          	print "\nTotal: $total\n";
          } else {
          	print "$total\n";
          }

          Comment

          Working...