/usr/share/munin/plugins/postfix_mailvolume is in munin-node 1.4.6-3ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
postfix_mailvolume - Plugin to monitor the volume of mails delivered
by postfix.
=head1 APPLICABLE SYSTEMS
Any postfix.
=head1 CONFIGURATION
The following shows the default configuration.
[postfix*]
env.logdir /var/log
env.logfile syslog
=head1 INTERPRETATION
The plugin shows the number of bytes of mail that has passed through
the postfix installation.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 BUGS
None known
=head1 VERSION
$Id: postfix_mailvolume.in 2314 2009-08-03 11:28:34Z ssm $
=head1 AUTHOR
Copyright (C) 2002-2008.
No author is documented.
=head1 LICENSE
GPLv2
=cut
use strict;
use Munin::Plugin;
my $pos = undef;
my $volume = 0;
my $LOGDIR = $ENV{'logdir'} || '/var/log';
my $LOGFILE = $ENV{'logfile'} || 'syslog';
sub parseLogfile {
my ($fname, $start) = @_;
my ($LOGFILE,$rotated) = tail_open($fname,$start);
my $line;
while ($line =<$LOGFILE>) {
chomp ($line);
if ($line =~ /qmgr.*from=.*size=([0-9]+)/) {
$volume += $1;
}
}
return tail_close($LOGFILE);
}
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
my $logfile;
`which postconf >/dev/null 2>/dev/null`;
if (!$?) {
$logfile = "$LOGDIR/$LOGFILE";
if (-f $logfile) {
if (-r "$logfile") {
print "yes\n";
exit 0;
} else {
print "no (logfile '$logfile' not readable)\n";
}
} else {
print "no (logfile '$logfile' not found)\n";
}
} else {
print "no (postfix not found)\n";
}
exit 0;
}
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_title Postfix bytes throughput\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel bytes / \${graph_period}\n";
print "graph_scale yes\n";
print "graph_category postfix\n";
print "volume.label throughput\n";
print "volume.type DERIVE\n";
print "volume.min 0\n";
exit 0;
}
my $logfile = "$LOGDIR/$LOGFILE";
if (! -f $logfile) {
print "volume.value U\n";
exit 1;
}
($pos,$volume) = restore_state();
if (!defined($volume)) {
# No state file present. Avoid startup spike: Do not read log
# file up to now, but remember how large it is now, and next
# time read from there.
$pos = (stat $logfile)[7]; # File size
$volume = 0;
} else {
$pos = parseLogfile ($logfile, $pos);
}
print "volume.value $volume\n";
save_state($pos,$volume);
# vim:syntax=perl
|