queue-size.pl
· 1.0 KiB · Perl
Orginalformat
#!/usr/bin/env perl
# postfix queue/s size
# author:
# source: http://tech.groups.yahoo.com/group/postfix-users/message/255133
# from: https://serverfault.com/questions/58196/how-do-i-check-the-postfix-queue-size
use strict;
use warnings;
use Symbol;
sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die "$0: opendir: $dir: $!\n";
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
++$c;
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count("$dir/$f");
}
}
closedir($dh) or die "closedir: $dir: $!\n";
return $c;
}
my $qdir = `postconf -h queue_directory`;
chomp($qdir);
chdir($qdir) or die "$0: chdir: $qdir: $!\n";
printf "Incoming: %d\n", count("incoming");
printf "Active: %d\n", count("active");
printf "Deferred: %d\n", count("deferred");
printf "Bounced: %d\n", count("bounce");
printf "Hold: %d\n", count("hold");
printf "Corrupt: %d\n", count("corrupt");
1 | #!/usr/bin/env perl |
2 | |
3 | # postfix queue/s size |
4 | # author: |
5 | # source: http://tech.groups.yahoo.com/group/postfix-users/message/255133 |
6 | # from: https://serverfault.com/questions/58196/how-do-i-check-the-postfix-queue-size |
7 | |
8 | use strict; |
9 | use warnings; |
10 | use Symbol; |
11 | sub count { |
12 | my ($dir) = @_; |
13 | my $dh = gensym(); |
14 | my $c = 0; |
15 | opendir($dh, $dir) or die "$0: opendir: $dir: $!\n"; |
16 | while (my $f = readdir($dh)) { |
17 | if ($f =~ m{^[A-F0-9]{5,}$}) { |
18 | ++$c; |
19 | } elsif ($f =~ m{^[A-F0-9]$}) { |
20 | $c += count("$dir/$f"); |
21 | } |
22 | } |
23 | closedir($dh) or die "closedir: $dir: $!\n"; |
24 | return $c; |
25 | } |
26 | my $qdir = `postconf -h queue_directory`; |
27 | chomp($qdir); |
28 | chdir($qdir) or die "$0: chdir: $qdir: $!\n"; |
29 | printf "Incoming: %d\n", count("incoming"); |
30 | printf "Active: %d\n", count("active"); |
31 | printf "Deferred: %d\n", count("deferred"); |
32 | printf "Bounced: %d\n", count("bounce"); |
33 | printf "Hold: %d\n", count("hold"); |
34 | printf "Corrupt: %d\n", count("corrupt"); |
35 |