To echo Jim's comment we do qmail queue monitoring with net-snmp as
well, and the attached script 'qmail-crick', plus the line in our
snmpd.conf:
exec .1.3.6.1.4.1.2021.52 qmail-crick /usr/local/bin/qmail-crick

This allows us to use the same script and delivery method for graphing
qmail queues in cricket as it does to test out queue threshold in our
monitoring system. This script and/or approach may or may not work for
you, but should serve to give you an idea of what is possible. We've found
the cricket-created graphs of mailqueue size very helpful in setting
reasonable limits for monitoring ; getting woken up at 3am to SIGALRM
qmail-send because you set your queue monitoring threshold too low is not
fun. On the other hand, early warning about new virii like SoBig variants
pounding your mailserver is good.


andrew

On Tue, 14 Oct 2003, Jim Trocki wrote:

> On Tue, 14 Oct 2003, David Nolan wrote:
>
> > I think you're better off sending success traps (upalerts), in a
> > 'heartbeat' mode, with a trap timeout configured.
>
> as another alternative, it wouldn't be a bad idea to install the
> net-snmp snmpd on the qmail hosts and configure them to run the qmail
> check mechanism via the "exec NAME PROG ARGS" mechanism in snmpd.conf,
> and have a monitor on the centralized mon server which polls for the
> results on each machine.
>
> this would allow you to check disk space and other stuff remotely, also.
>
> _______________________________________________
> mon mailing list
> [EMAIL PROTECTED]
> http://linux.kernel.org/mailman/listinfo/mon
>
>
#!/usr/bin/perl
#
# NAME
#  qmail-crick
#
#
# SYNOPSIS
#  qmail-crick [-v]
#
#
# DESCRIPTION
#  Outputs some qmail stats for use by Cricket.
#  Specifically, one per line and in this order, the following data:
#   current local deliveries outstanding
#   concurrencylocal
#   current remote deliveries outstanding
#   concurrencyremote
#   msgs in local queue
#   msgs in remote queue
#   msgs in to-do queue
#
#  If no data is available, a 'U' is printed. Cricket knows to 
#  interpret this as meaning 'no data is available'.
#
#
# USAGE
#  Drop it somewhere. Make sure perl is installed, and qmail.
#  You need to run it as root, or another user with perms to read
#  the qmail queue dir.
#
#
# NOTES
#  Some design inspired by qmail-mrtg scripts on the net, in particular
#  qmHandle. The ones I saw on the net mostly involved parsing log files
#  and looked like they would get painful, quickly. This script
#  should have essentially constant run-time and should run under
#  any remotely standard qmail configuration.
#
#
# BUGS
#  If you've changed concurrency{remote,local} in files but haven't
#  yet restarted qmail-send (or the restart hasn't taken effect),
#  this script erroneously reports the changed values.
#
#  This was deemed an acceptable risk, as concurrency settings
#  don't change much and when they do, you restart qmail-send,
#  right?
#
#
# AUTHOR
# Andrew Ryan <[EMAIL PROTECTED]>
# $Id: qmail-crick,v 1.2 2001/09/18 21:59:49 andrewr Exp $
#
#

use strict;
use Getopt::Std;

use vars qw($opt_v);

Getopt::Std::getopts('v') || &printUsage;

sub printUsage {
  print "$0: Usage: $0 [-vh]\n";
  print "  -v  Verbose mode\n";
  print "  -h  This help message\n";
  print "\n";
  exit 1;
}

#
# Use the most generic ps possible. This works on (at least) linux
# and solaris, probably others as well.
#
my $ps_cmd = "ps -ec";

#
# Where to find qmail
#
my $qmail_basedir = "/var/qmail";

# Default values for concurrency (compiled into binary)
my $concurrencyremote = 20;
my $concurrencylocal = 10;

my $remote_conc_file = "$qmail_basedir/control/concurrencyremote";
my $local_conc_file = "$qmail_basedir/control/concurrencylocal";
my $queue_dir = "$qmail_basedir/queue";

my ($local_conc, $remote_conc, $exe_name);
my ($local_qsize, $remote_qsize, $todo_qsize);


#
# Get concurrencyremote
#
if ( -f $remote_conc_file) {
    if (open (CONC, "$remote_conc_file")) {
        chomp($concurrencyremote = <CONC>) ;
    } else {
        print STDERR "Unable to open file '$remote_conc_file': $!";
        exit 1;
    }
    close CONC;
} else {
    print STDERR "File $remote_conc_file not found, assuming default concurrencyremote 
of $concurrencyremote\n" if $opt_v;
}

#
# Get concurrencylocal
#
if ( -f $local_conc_file) {
    if (open (CONC, "$local_conc_file")) {
        chomp($concurrencylocal = <CONC>) ;
    } else {
        print STDERR "Unable to open file '$local_conc_file': $!";
        exit 1;
    }
    close CONC;
} else {
    print STDERR "File $local_conc_file not found, assuming default concurrencylocal 
of $concurrencylocal\n" if $opt_v;
}


#
# Get local and remote concurrency by looking as ps
#
$local_conc = 0;
$remote_conc = 0;
if (open (PS, "$ps_cmd |")) {
      while (<PS>) {
        chomp;
        @_=split(' ',$_);
        $exe_name = $_[-1];
        #print "Found exe named '$exe_name'\n" if $opt_v ; #DEBUG
        $local_conc++ if $exe_name =~ /^qmail-local$/;
        $remote_conc++ if $exe_name =~ /^qmail-remote$/;
     }
     unless (close (PS)) {
        print STDERR "Unable to fork '$ps_cmd': $!";
        exit 1;
     }
} else {
    print STDERR "Unable to fork '$ps_cmd': $!";
    exit 1;
}



$remote_qsize = &NumQueuedMsgs("$queue_dir/remote");
$local_qsize = &NumQueuedMsgs("$queue_dir/local");
$todo_qsize = &NumQueuedMsgs("$queue_dir/todo");


printf ("%d current outstanding local\n", $local_conc);
printf ("%d concurrencylocal\n", $concurrencylocal);
printf ("%d current outstanding remote\n", $remote_conc);
printf ("%d concurrencyremote\n", $concurrencyremote);
printf ("%d local queue length\n", $local_qsize);
printf ("%d remote queue length\n", $remote_qsize);
printf ("%d not-yet-preprocessed queue length\n", $todo_qsize);
exit 0;



#
# Given a queue directory to look into, descends into all subdirs of
# that dir and counts files (i.e. queued messages).
# Returns "U" if dir could not be opened (does not exist or you don't
#            have permissions to read it)
# Otherwise, returns number of messages in queue.
#
sub NumQueuedMsgs {
  my ($qdir) = (@_);
  my ($dir, @dirlist);
  my $qsize = 0;
  # Make list of messages in remote queue (thanks Franky Van Liedekerke)
  if (opendir(DIR,$qdir)) {
    @dirlist = grep !/\./, readdir DIR;
    closedir DIR;
    foreach $dir (@dirlist) {
      opendir (SUBDIR,"$qdir/$dir");
      $qsize += scalar(grep !/\./, map "$dir/$_", readdir SUBDIR);
      closedir SUBDIR;
    }
    return $qsize;
  } else {
    print STDERR "Unable to open queue dir ${queue_dir}/remote: $!\n";
    return "U";
  }
}
_______________________________________________
mon mailing list
[EMAIL PROTECTED]
http://linux.kernel.org/mailman/listinfo/mon

Reply via email to