После того, как нагляделся на nagios у знакомых, решил таки поднять себе munin.
Разумеется, поставил и настроил в
основном без проблем. Когда стал смотреть, оказалось, что существуют некоторые сложности с плагинами.
К примеру, берём плагин postfix_mailvolume:
code perl
#!/usr/bin/perl -w
=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 1532 2008-03-04 20:10:28Z janl $
=head1 AUTHOR
Copyright (C) 2002-2008.
No author is documented.
=head1 LICENSE
GPLv2
=cut
use strict;
use Munin::Plugin;
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>) {
if ($line =~ /qmgr.*from=.*size=([0-9]+)/) {
$volume += $1;
}
}
}
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") {
} else {
print "no (logfile '$logfile' not readable)\n";
}
} else {
print "no (logfile '$logfile' not found)\n";
}
} else {
print "no (postfix not found)\n";
}
}
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";
}
my $logfile = "$LOGDIR/$LOGFILE";
if (! -f $logfile) {
print "delivered.value U\n";
}
($pos,$volume) = restore_state();
# 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
После внесения соответствующих моей системе изменений и запуска оного плагина, в логах мунина идёт ругань на delivered, который ранее не был определён. Ок, правим далее:
code bash
# diff postfix_mailvolume postfix_mailvolume.orig
56c56
< my $LOGFILE = $ENV{'logfile'} || 'mail.log';
---
> my $LOGFILE = $ENV{'logfile'} || 'syslog';
115c115
< print "volume.value Unknown\n";
---
> print "delivered.value U\n";
Перезапускаем munin-node, вроде ругани в логах нет. Пробуем исполнить этот файл:
code bash
# sudo -u munin ./postfix_mailvolume
volume.value 32625
# sudo -u munin ./postfix_mailvolume config
graph_title Postfix bytes throughput
graph_args --base 1000 -l 0
graph_vlabel bytes / ${graph_period}
graph_scale yes
graph_category postfix
volume.label throughput
volume.type DERIVE
volume.min 0
# sudo -u munin ./postfix_mailvolume autoconf
yes
Всё вроде в порядке, файл /var/lib/munin/plugin-state/postfix_mailvolume создался автоматом и меняет свои значения после каждого распарсивания:
code text
%MUNIN-STATE1.0
153602792
32625
Вот только график не строится. Не показываются изменения. Шоделать?