#!/usr/bin/perl -w use strict; my $spool = '/var/spool/courier'; my $queue = '/var/spool/courier/msgq/*'; my $delay = shift @ARGV || 5; my $count = shift @ARGV; my $watching = 1; my $old_total = undef; my $old_time = undef; my $start_time = undef; my $start_total = undef; while ($watching) { my $time = time; my $msgs = qx(find $spool/msgs -name 'D*'| wc -l); my $tmp = qx(find $spool/tmp -name 'D*' | wc -l); chomp ($msgs, $tmp); $msgs += 0; $tmp += 0; my $total = $msgs + $tmp; my $change = defined $old_total ? $total - $old_total : 0; my $tot_change = defined $start_total ? $total - $start_total : 0; printf("%02d:%02d:%02d %6d %4d (%5d) %6.2f/sec (%6.2f/sec)\n", (localtime($time))[2,1,0], # $msgs, $tmp, $total, $change, $tot_change, defined $old_time ? (1 * $change)/($time-$old_time) : 0, defined $start_time ? (1 * $tot_change)/($time-$start_time) : 0 ); $old_total = $total; $old_time = $time; $start_time = $time unless defined $start_time; $start_total = $total unless defined $start_total; sleep $delay if $delay and (not defined $count or $count > 1); if (defined $count) { --$count; $watching = 0 if $count <= 0; } } __END__ =head1 NAME watch-mailq.pl - Give a running count of messages in Courier's mail queue. =head1 SYSNOPSIS watch-mailq.pl [delay] [repeat] =head1 DESCRIPTION =over 4 =item delay Delay in seconds between checks. (Default: 5 sec) =item repeat Number of times to repeat the check. (Default: forever) =back B The rate of change in the queue is I the number of messages processed per second. It only measures the change in the number of messages still in the queue. =head1 LICENSE Copyright (c) 2003 Randy Smith All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =head1 AUTHOR Randy Smith =cut