root / plugins / amavis / amavis_ @ c4b2d9a8
Historique | Voir | Annoter | Télécharger (5,8 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor amavisd-new statistics. Values are retrieved by querying |
| 4 |
# the BerkeleyDB database 'snmp.db', in which amavisd-new stores its |
| 5 |
# statistics. |
| 6 |
# |
| 7 |
# The plugin requires the Perl module BerkeleyDB. |
| 8 |
# |
| 9 |
# To use, setup /etc/munin/plugin-conf.d/amavis e.g. as follows: |
| 10 |
# |
| 11 |
# [amavis_*] |
| 12 |
# env.amavis_db_home /var/lib/amavis/db |
| 13 |
# user amavis |
| 14 |
# |
| 15 |
# Where env.amavis_db_home is the path to the amavisd-new BerkeleyDB files |
| 16 |
# (/var/amavis/db by default). |
| 17 |
# |
| 18 |
# Then create symlinks in the Munin plugin directory named "amavis_time", |
| 19 |
# "amavis_cache" and "amavis_content", or use munin-node-configure. |
| 20 |
# |
| 21 |
# Parameters: |
| 22 |
# |
| 23 |
# config |
| 24 |
# autoconf |
| 25 |
# suggest |
| 26 |
# |
| 27 |
# Config variables: |
| 28 |
# |
| 29 |
# amavis_db_home - where the amavisd-new berkeley db files are located |
| 30 |
# |
| 31 |
# Magic markers |
| 32 |
#%# family=auto |
| 33 |
#%# capabilities=autoconf |
| 34 |
#%# capabilities=suggest |
| 35 |
|
| 36 |
use strict; |
| 37 |
no warnings 'uninitialized'; |
| 38 |
|
| 39 |
use BerkeleyDB; |
| 40 |
|
| 41 |
my($dbfile) = 'snmp.db'; |
| 42 |
my($db_home) = # DB databases directory |
| 43 |
defined $ENV{'amavis_db_home'} ? $ENV{'amavis_db_home'} : '/var/amavis/db';
|
| 44 |
|
| 45 |
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
| 46 |
if (-x "/usr/sbin/amavisd-agent") {
|
| 47 |
print "yes\n"; |
| 48 |
exit 0; |
| 49 |
} else {
|
| 50 |
print "no (/usr/sbin/amavisd-agent not found or not executable)\n"; |
| 51 |
exit 1; |
| 52 |
} |
| 53 |
} elsif ($ARGV[0] and $ARGV[0] eq "suggest") {
|
| 54 |
print "time\n"; |
| 55 |
print "cache\n"; |
| 56 |
print "content\n"; |
| 57 |
exit 0; |
| 58 |
} |
| 59 |
|
| 60 |
my $stats_type = ""; |
| 61 |
if ($0 =~ /^(?:|.*\/)amavis_(cache|content|time)$/) {
|
| 62 |
$stats_type = $1; |
| 63 |
} else {
|
| 64 |
print "You need to create a symlink to this plugin called either amavis_cache, amavis_time or amavis_content to be able to use it.\n"; |
| 65 |
exit 2; |
| 66 |
} |
| 67 |
|
| 68 |
if ($ARGV[0] and $ARGV[0] eq "config") {
|
| 69 |
if ($stats_type eq "cache") {
|
| 70 |
print "graph_title Amavis cache hit / miss ratio\n"; |
| 71 |
print "graph_args --lower-limit 0 --upper-limit 100 --rigid\n"; |
| 72 |
print "graph_category antivirus\n"; |
| 73 |
print "graph_info The ratio of cache hits and misses for AMaViSd-new.\n"; |
| 74 |
print "graph_order hits misses\n"; |
| 75 |
print "graph_scale no\n"; |
| 76 |
print "graph_vlabel %\n"; |
| 77 |
print "hits.label Cache hits\n"; |
| 78 |
print "hits.draw AREA\n"; |
| 79 |
print "hits.max 100\n"; |
| 80 |
print "hits.min 0\n"; |
| 81 |
print "misses.label Cache misses\n"; |
| 82 |
print "misses.draw STACK\n"; |
| 83 |
print "misses.max 100\n"; |
| 84 |
print "misses.min 0\n"; |
| 85 |
} elsif ($stats_type eq "content") {
|
| 86 |
print "graph_title Amavis scanned mails\n"; |
| 87 |
print "graph_category antivirus\n"; |
| 88 |
print "graph_period minute\n"; |
| 89 |
print "graph_vlabel msgs / \${graph_period}\n";
|
| 90 |
foreach my $type (qw(total clean spam spammy virus)) {
|
| 91 |
print "$type.label " . ucfirst($type) . " mails \n"; |
| 92 |
print "$type.type DERIVE\n"; |
| 93 |
print "$type.min 0\n"; |
| 94 |
} |
| 95 |
print "clean.info Legitimate mail.\n"; |
| 96 |
print "spammy.info Mails with a spam score above the tag2 level.\n"; |
| 97 |
print "spam.info Mails with a spam score above the kill level for spam.\n"; |
| 98 |
print "virus.info Mails with a virus.\n"; |
| 99 |
print "total.info Total number of scanned mails.\n"; |
| 100 |
} elsif ($stats_type eq "time") {
|
| 101 |
print "graph_title Amavis average scan time\n"; |
| 102 |
print "graph_info Average time spent in each phase of the mail scanning process, per mail.\n"; |
| 103 |
print "graph_category antivirus\n"; |
| 104 |
print "graph_vlabel sec / mail\n"; |
| 105 |
print "graph_scale no\n"; |
| 106 |
|
| 107 |
print "msgs.label Total number of messages\n"; |
| 108 |
print "msgs.graph no\n"; |
| 109 |
print "msgs.type DERIVE\n"; |
| 110 |
print "msgs.min 0\n"; |
| 111 |
|
| 112 |
foreach my $type (qw(decoding receiving sending spamcheck viruscheck total)) {
|
| 113 |
print "${type}.label " . ucfirst($type) . "\n";
|
| 114 |
print "${type}.type DERIVE\n";
|
| 115 |
print "${type}.min 0\n";
|
| 116 |
print "${type}.cdef ${type},1000,/,msgs,/\n";
|
| 117 |
} |
| 118 |
} |
| 119 |
exit 0; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
my ($env, $db, @dbstat, $cursor); |
| 124 |
|
| 125 |
@dbstat = stat("$db_home/$dbfile");
|
| 126 |
my $errn = @dbstat ? 0 : 0+$!; |
| 127 |
$errn == 0 or die "stat $db_home/$dbfile: $!"; |
| 128 |
|
| 129 |
$env = BerkeleyDB::Env->new( |
| 130 |
-Home => $db_home, |
| 131 |
-Flags => DB_INIT_CDB | DB_INIT_MPOOL, |
| 132 |
-ErrFile => \*STDOUT, |
| 133 |
-Verbose => 1, |
| 134 |
); |
| 135 |
defined $env or die "BDB no env: $BerkeleyDB::Error $!"; |
| 136 |
|
| 137 |
$db = BerkeleyDB::Hash->new(-Filename => $dbfile, -Env => $env); |
| 138 |
defined $db or die "BDB no db: $BerkeleyDB::Error $!"; |
| 139 |
|
| 140 |
my %values = (); |
| 141 |
my ($eval_stat, $stat, $key, $val); |
| 142 |
|
| 143 |
$cursor = $db->db_cursor; # obtain read lock |
| 144 |
defined $cursor or die "db_cursor error: $BerkeleyDB::Error"; |
| 145 |
|
| 146 |
while (($stat = $cursor->c_get($key, $val, DB_NEXT)) == 0) {
|
| 147 |
$values{$key} = $val;
|
| 148 |
} |
| 149 |
|
| 150 |
$stat == DB_NOTFOUND or die "c_get: $BerkeleyDB::Error $!"; |
| 151 |
$cursor->c_close == 0 or die "c_close error: $BerkeleyDB::Error"; |
| 152 |
$cursor = undef; |
| 153 |
|
| 154 |
$eval_stat = $@; |
| 155 |
|
| 156 |
if ($eval_stat ne '') { chomp($eval_stat); die "BDB $eval_stat\n"; }
|
| 157 |
|
| 158 |
for my $k (sort keys %values) {
|
| 159 |
if ($values{$k} =~ /^(?:C32|C64) (.*)\z/) {
|
| 160 |
$values{$k} = $1;
|
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
if ($stats_type eq "cache") {
|
| 165 |
my $hits = $values{'CacheHits'};
|
| 166 |
my $misses = $values{'CacheMisses'};
|
| 167 |
my $misses_ratio = $misses * 100.00 / ($hits + $misses); |
| 168 |
my $hits_ratio = $hits * 100.00 / ($hits + $misses); |
| 169 |
|
| 170 |
printf("hits.value %.1f\n", $hits_ratio);
|
| 171 |
printf("misses.value %.1f\n", $misses_ratio);
|
| 172 |
} elsif ($stats_type eq "content") {
|
| 173 |
printf("total.value %d\n", $values{'InMsgs'});
|
| 174 |
my $clean = $values{'ContentCleanMsgs'};
|
| 175 |
if (defined($values{'ContentCleanTagMsgs'})) {
|
| 176 |
$clean += $values{'ContentCleanTagMsgs'};
|
| 177 |
} |
| 178 |
printf("clean.value %d\n", $clean);
|
| 179 |
printf("spam.value %d\n", $values{'ContentSpamMsgs'});
|
| 180 |
printf("spammy.value %d\n", $values{'ContentSpammyMsgs'});
|
| 181 |
printf("virus.value %d\n", $values{'ContentVirusMsgs'});
|
| 182 |
} elsif ($stats_type eq "time") {
|
| 183 |
printf("decoding.value %d\n", $values{'TimeElapsedDecoding'});
|
| 184 |
printf("receiving.value %d\n", $values{'TimeElapsedReceiving'});
|
| 185 |
printf("sending.value %d\n", $values{'TimeElapsedSending'});
|
| 186 |
printf("spamcheck.value %d\n", $values{'TimeElapsedSpamCheck'});
|
| 187 |
printf("viruscheck.value %d\n", $values{'TimeElapsedVirusCheck'});
|
| 188 |
printf("total.value %d\n", $values{'TimeElapsedTotal'});
|
| 189 |
printf("msgs.value %d\n", $values{'InMsgs'});
|
| 190 |
} |
| 191 |
|
| 192 |
$db->db_close == 0 or die "BDB db_close error: $BerkeleyDB::Error $!"; |
