3
# Plugin to monitor the volume of mails delivered by postfix.
5
# Usage: copy or link into /etc/munin/node.d/
10
# autoconf (optional - used by munin-config)
14
# logdir - Which logfile to use
15
# logfile - What file to read in logdir
17
# $Log: postfix_mailvolume.in,v $
18
# Revision 1.1 2004/01/02 18:50:00 jimmyo
19
# Renamed occurrances of lrrd -> munin
21
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
22
# Import of LRRD CVS tree after renaming to Munin
24
# Revision 1.1 2003/11/26 14:45:34 jimmyo
27
# Revision 1.7 2003/11/15 11:10:28 jimmyo
30
# Revision 1.6 2003/11/07 17:43:16 jimmyo
31
# Cleanups and log entries
35
# Magic markers (optional - used by munin-config and some installation
39
#%# capabilities=autoconf
41
my $statefile = "@@PLUGSTATE@@/munin-plugin-postfix_mailvolume.state";
44
my $LOGDIR = $ENV{'logdir'} || '/var/log';
45
my $LOGFILE = $ENV{'logfile'} || 'syslog';
48
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
53
$logfile = "$LOGDIR/$LOGFILE";
64
print "no (logfile not readable)\n";
69
print "no (logfile not found)\n";
74
print "no (could not find logdir)\n";
80
my $logfile = "$LOGDIR/$LOGFILE";
81
my $prevdate = get_prev_date();
83
if (-f "$logfile.$prevdate")
85
$rotlogfile = "$logfile.$prevdate";
87
elsif (-f "$logfile.0")
89
$rotlogfile = $logfile . ".0";
91
elsif (-f "$logfile.1")
93
$rotlogfile = $logfile . ".1";
95
elsif (-f "$logfile.01")
97
$rotlogfile = $logfile . ".01";
101
$rotlogfile = $logfile . ".0";
106
open (IN, "$statefile") or exit 4;
107
if (<IN> =~ /^(\d+):(\d+)/)
109
($pos, $volume) = ($1, $2);
114
if (! -f $logfile and ! -f $rotlogfile)
116
print "delivered.value U\n";
121
$startsize = (stat $logfile)[7];
129
if ($startsize < $pos)
132
parseLogfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
136
parseLogfile ($logfile, $pos, $startsize);
139
if ( $ARGV[0] and $ARGV[0] eq "config" )
141
print "graph_title Postfix mail throughput\n";
142
print "graph_args --base 1000 -l 0\n";
143
print "graph_vlabel bytes / min\n";
144
print "graph_scale no\n";
145
print "volume.label throughput\n";
146
print "volume.type DERIVE\n";
147
print "volume.cdef volume,60,*\n";
148
print "volume.min 0\n";
152
print "volume.value $volume\n";
155
die("$statefile is a symbolic link, refusing to touch it.");
157
open (OUT, ">$statefile") or exit 4;
158
print OUT "$pos:$volume\n";
163
my ($fname, $start, $stop) = @_;
164
open (LOGFILE, $fname) or exit 3;
165
seek (LOGFILE, $start, 0) or exit 2;
167
while (tell (LOGFILE) < $stop)
172
if ($line =~ /qmgr.*from=.*size=([0-9]+)/)
182
my @date = localtime (time - 86400);
183
my $prevdate = $date[5]+1900 . $date[4]+1 . $date[3];