1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Category Tree: reduce number of categories

This commit is contained in:
dipohl 2017-02-22 04:48:52 +01:00
parent 84c28707eb
commit c4b2d9a8e3
22 changed files with 377 additions and 377 deletions

View file

@ -1,242 +1,126 @@
#!/usr/bin/perl
#! /bin/bash
#
# Munin Plugin
# to count logins to your dovecot mailserver
#
# Created by Dominik Schulz <lkml@ds.gauner.org>
# http://developer.gauner.org/munin/
# Contributions by:
# - Stephane Enten <tuf@delyth.net>
# - Steve Schnepp <steve.schnepp@pwkf.org>
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# Config variables:
#
# logfile - Where to find the syslog file
#
# Add the following line to a file in /etc/munin/plugin-conf.d:
# env.logfile /var/log/your/logfile.log
#
# Magic markers (optional - used by munin-config and installation scripts):
#
#%# family=auto
#%# capabilities=autoconf
use Munin::Plugin;
######################
# Configuration
######################
EXPR_BIN=/usr/bin/expr
LOGFILE=${logfile:-/var/log/mail.log}
######################
$pos = undef;
$connected = 0;
$connectedimap = 0;
$connectedpop3 = 0;
$connections = 0;
$connectionsimap = 0;
$connectionspop3 = 0;
$login = 0;
$pop3login = 0;
$imaplogin = 0;
$tls = 0;
$ssl = 0;
$aborted = 0;
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
($dirname = $0) =~ s/[^\/]+$//;
if [ "$1" = "config" ]; then
echo 'graph_title Dovecot Logins'
echo 'graph_category mail'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel Login Counters'
$dovelogfile = 0 ;
for t in Total TLS SSL IMAP POP3
do
field=$(echo $t | tr '[:upper:]' '[:lower:]')
echo "login_$field.label $t Logins"
echo "login_$field.type DERIVE"
echo "login_$field.min 0"
done
$logfile = $ENV{'LOGFILE'} || '/var/log/mail.log';
echo 'connected.label Connected Users'
if ( $logfile =~ /dovecot/ ) {
$dovelogfile = 1 ;
}
exit 0
fi
# Use an overrided $PATH for all external programs if needed
$DOVEADM = "doveadm";
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
if (! -x $DOVEADM) {
print "no (no doveadm)\n";
exit(1);
}
if (! -f $logfile) {
print "no (logfile $logfile does not exist)\n";
exit(1);
}
if (-r "$logfile") {
print "yes\n";
exit 0;
} else {
print "no (logfile not readable)\n";
}
exit 1;
}
if (-f "$logfile.0") {
$rotlogfile = $logfile . ".0";
} elsif (-f "$logfile.1") {
$rotlogfile = $logfile . ".1";
} elsif (-f "$logfile.01") {
$rotlogfile = $logfile . ".01";
} else {
$rotlogfile = $logfile . ".0";
}
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
print "multigraph dovecot_connections\n";
print "graph_title Dovecot connections\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel connections\n";
print "graph_category mail\n";
print "connections.label Connections open\n";
print "connections.type GAUGE\n";
print "connections.draw LINE1\n";
print "connections.min 0\n";
print "connectionsimap.label IMAP\n";
print "connectionsimap.type GAUGE\n";
print "connectionsimap.draw AREA\n";
print "connectionsimap.min 0\n";
print "connectionspop3.label POP3\n";
print "connectionspop3.type GAUGE\n";
print "connectionspop3.draw STACK\n";
print "connectionspop3.min 0\n";
print "multigraph dovecot_connected\n";
print "graph_title Dovecot connected users\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel connections\n";
print "graph_category mail\n";
print "connected.label Connected users\n";
print "connected.type GAUGE\n";
print "connected.draw LINE1\n";
print "connected.min 0\n";
print "connectedimap.label IMAP\n";
print "connectedimap.type GAUGE\n";
print "connectedimap.draw AREA\n";
print "connectedimap.min 0\n";
print "connectedpop3.label POP3\n";
print "connectedpop3.type GAUGE\n";
print "connectedpop3.draw STACK\n";
print "connectedpop3.min 0\n";
print "multigraph dovecot_logins\n";
print "graph_title Dovecot logins\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel logins/5 minute\n";
print "graph_category mail\n";
print "login.label Logins\n";
print "login.type GAUGE\n";
print "login.draw LINE1\n";
print "login.min 0\n";
print "imaplogin.label IMAP logins\n";
print "imaplogin.type GAUGE\n";
print "imaplogin.draw LINE1\n";
print "imaplogin.min 0\n";
print "pop3login.label POP3 logins\n";
print "pop3login.type GAUGE\n";
print "pop3login.draw LINE1\n";
print "pop3login.min 0\n";
print "tls.label TLS\n";
print "tls.type GAUGE\n";
print "tls.draw LINE1\n";
print "tls.min 0\n";
print "ssl.label SSL\n";
print "ssl.type GAUGE\n";
print "ssl.draw LINE1\n";
print "ssl.min 0\n";
print "aborted.label Aborted logins\n";
print "aborted.type GAUGE\n";
print "aborted.draw LINE1\n";
print "aborted.min 0\n";
exit 0;
}
if (! -f $logfile and ! -f $rotlogfile) {
print "multigraph dovecot_connections\n";
print "connections.value U";
print "connectionsimap.value U";
print "connectionspop3.value U";
print "multigraph dovecot_connected\n";
print "connected.value U\n";
print "connectedimap.value U\n";
print "connectedpop3.value U\n";
print "multigraph dovecot_logins\n";
print "login.value U\n";
print "pop3login.value U\n";
print "imaplogin.value U\n";
print "tls.value U\n";
print "ssl.value U\n";
print "aborted.value U\n";
exit 0;
}
# dit kan beter maar twee calls zijn toch nodig als we niet zelf aggegreren
# suggestie: doveadm who -1 | awk '{print $1" "$2" "$4}' | sort | uniq -c
$connectedimap = `$DOVEADM -f flow who | grep imap | wc -l`;
$connectedpop3 = `$DOVEADM -f flow who | grep pop3 | wc -l`;
$connectionsimap = `$DOVEADM -f flow who -1 | grep imap | wc -l`;
$connectionspop3 = `$DOVEADM -f flow who -1 | grep pop3 | wc -l`;
#trim
$connectedimap =~ s/\s+$//;
$connectedpop3 =~ s/\s+$//;
$connectionsimap =~ s/\s+$//;
$connectionspop3 =~ s/\s+$//;
$connected = $connectedimap + $connectedpop3;
$connections = $connectionsimap + $connectionspop3;
my ($pos) = restore_state();
$startsize = (stat $logfile)[7];
if (!defined $pos) {
# Initial run.
$pos = $startsize;
}
if ($startsize < $pos) {
# Log rotated
parseDovecotfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
$pos = 0;
}
parseDovecotfile ($logfile, $pos, $startsize);
$pos = $startsize;
save_state($pos);
print "multigraph dovecot_connections\n";
print "connections.value $connections\n";
print "connectionsimap.value $connectionsimap\n";
print "connectionspop3.value $connectionspop3\n";
print "multigraph dovecot_connected\n";
print "connected.value $connected\n";
print "connectedimap.value $connectedimap\n";
print "connectedpop3.value $connectedpop3\n";
print "multigraph dovecot_logins\n";
print "login.value $login\n";
print "pop3login.value $pop3login\n";
print "imaplogin.value $imaplogin\n";
print "tls.value $tls\n";
print "ssl.value $ssl\n";
print "aborted.value $aborted\n";
sub parseDovecotfile {
my ($fname, $start, $stop) = @_;
open (logf, $fname) or exit 3;
seek (logf, $start, 0) or exit 2;
while (tell (logf) < $stop) {
my $line =<logf>;
chomp ($line);
if ( $dovelogfile == 0 and $line !~ m/dovecot/) { next; }
else {
if ($line =~ m/Aborted/) {
$aborted++;
} elsif ($line =~ m/Login:/) {
$login++;
if ( $line =~ m/TLS/) {
$tls++;
} elsif ($line =~ m/SSL/) {
$ssl++;
}
if ( $line =~ m/pop3-login:/) {
$pop3login++;
} elsif ($line =~ m/imap-login:/) {
$imaplogin++;
}
}
}
}
close(logf);
}
# vim:syntax=perl
######################
# Total Logins
######################
echo -en "login_total.value "
VALUE=$(egrep -c '[dovecot]?.*Login' $LOGFILE)
if [ ! -z "$VALUE" ]; then
echo "$VALUE"
else
echo "0"
fi
echo -n
######################
# Connected Users
######################
DISCONNECTS=$(egrep -c '[dovecot]?.*Disconnected' $LOGFILE)
CONNECTS=$(egrep -c '[dovecot]?.*Login' $LOGFILE)
VALUE=$($EXPR_BIN $CONNECTS - $DISCONNECTS)
if [ -z "$VALUE" ] || [ "$VALUE" -lt 0 ]; then
VALUE=0
fi
echo -en "connected.value "
echo $VALUE
echo -n
######################
# TLS Logins
######################
echo -en "login_tls.value "
VALUE=$(egrep -c '[dovecot]?.*Login.*TLS' $LOGFILE)
if [ ! -z "$VALUE" ]; then
echo "$VALUE"
else
echo "0"
fi
echo -n
######################
# SSL Logins
######################
echo -en "login_ssl.value "
VALUE=$(egrep -c '[dovecot]?.*Login.*SSL' $LOGFILE)
if [ ! -z "$VALUE" ]; then
echo "$VALUE"
else
echo "0"
fi
echo -n
######################
# IMAP Logins
######################
echo -en "login_imap.value "
VALUE=$(egrep -c '[dovecot]?.*imap.*Login' $LOGFILE)
if [ ! -z "$VALUE" ]; then
echo "$VALUE"
else
echo "0"
fi
echo -n
######################
# POP3 Logins
######################
echo -en "login_pop3.value "
VALUE=$(egrep -c '[dovecot]?.*pop3.*Login' $LOGFILE)
if [ ! -z "$VALUE" ]; then
echo "$VALUE"
else
echo "0"
fi
echo -n

242
plugins/dovecot/dovecot1 Executable file
View file

@ -0,0 +1,242 @@
#!/usr/bin/perl
#%# family=auto
#%# capabilities=autoconf
use Munin::Plugin;
$pos = undef;
$connected = 0;
$connectedimap = 0;
$connectedpop3 = 0;
$connections = 0;
$connectionsimap = 0;
$connectionspop3 = 0;
$login = 0;
$pop3login = 0;
$imaplogin = 0;
$tls = 0;
$ssl = 0;
$aborted = 0;
($dirname = $0) =~ s/[^\/]+$//;
$dovelogfile = 0 ;
$logfile = $ENV{'LOGFILE'} || '/var/log/mail.log';
if ( $logfile =~ /dovecot/ ) {
$dovelogfile = 1 ;
}
# Use an overrided $PATH for all external programs if needed
$DOVEADM = "doveadm";
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
if (! -x $DOVEADM) {
print "no (no doveadm)\n";
exit(1);
}
if (! -f $logfile) {
print "no (logfile $logfile does not exist)\n";
exit(1);
}
if (-r "$logfile") {
print "yes\n";
exit 0;
} else {
print "no (logfile not readable)\n";
}
exit 1;
}
if (-f "$logfile.0") {
$rotlogfile = $logfile . ".0";
} elsif (-f "$logfile.1") {
$rotlogfile = $logfile . ".1";
} elsif (-f "$logfile.01") {
$rotlogfile = $logfile . ".01";
} else {
$rotlogfile = $logfile . ".0";
}
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
print "multigraph dovecot_connections\n";
print "graph_title Dovecot connections\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel connections\n";
print "graph_category mail\n";
print "connections.label Connections open\n";
print "connections.type GAUGE\n";
print "connections.draw LINE1\n";
print "connections.min 0\n";
print "connectionsimap.label IMAP\n";
print "connectionsimap.type GAUGE\n";
print "connectionsimap.draw AREA\n";
print "connectionsimap.min 0\n";
print "connectionspop3.label POP3\n";
print "connectionspop3.type GAUGE\n";
print "connectionspop3.draw STACK\n";
print "connectionspop3.min 0\n";
print "multigraph dovecot_connected\n";
print "graph_title Dovecot connected users\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel connections\n";
print "graph_category mail\n";
print "connected.label Connected users\n";
print "connected.type GAUGE\n";
print "connected.draw LINE1\n";
print "connected.min 0\n";
print "connectedimap.label IMAP\n";
print "connectedimap.type GAUGE\n";
print "connectedimap.draw AREA\n";
print "connectedimap.min 0\n";
print "connectedpop3.label POP3\n";
print "connectedpop3.type GAUGE\n";
print "connectedpop3.draw STACK\n";
print "connectedpop3.min 0\n";
print "multigraph dovecot_logins\n";
print "graph_title Dovecot logins\n";
print "graph_args --base 1000 -l 0 --no-gridfit --slope-mode\n";
print "graph_vlabel logins/5 minute\n";
print "graph_category mail\n";
print "login.label Logins\n";
print "login.type GAUGE\n";
print "login.draw LINE1\n";
print "login.min 0\n";
print "imaplogin.label IMAP logins\n";
print "imaplogin.type GAUGE\n";
print "imaplogin.draw LINE1\n";
print "imaplogin.min 0\n";
print "pop3login.label POP3 logins\n";
print "pop3login.type GAUGE\n";
print "pop3login.draw LINE1\n";
print "pop3login.min 0\n";
print "tls.label TLS\n";
print "tls.type GAUGE\n";
print "tls.draw LINE1\n";
print "tls.min 0\n";
print "ssl.label SSL\n";
print "ssl.type GAUGE\n";
print "ssl.draw LINE1\n";
print "ssl.min 0\n";
print "aborted.label Aborted logins\n";
print "aborted.type GAUGE\n";
print "aborted.draw LINE1\n";
print "aborted.min 0\n";
exit 0;
}
if (! -f $logfile and ! -f $rotlogfile) {
print "multigraph dovecot_connections\n";
print "connections.value U";
print "connectionsimap.value U";
print "connectionspop3.value U";
print "multigraph dovecot_connected\n";
print "connected.value U\n";
print "connectedimap.value U\n";
print "connectedpop3.value U\n";
print "multigraph dovecot_logins\n";
print "login.value U\n";
print "pop3login.value U\n";
print "imaplogin.value U\n";
print "tls.value U\n";
print "ssl.value U\n";
print "aborted.value U\n";
exit 0;
}
# dit kan beter maar twee calls zijn toch nodig als we niet zelf aggegreren
# suggestie: doveadm who -1 | awk '{print $1" "$2" "$4}' | sort | uniq -c
$connectedimap = `$DOVEADM -f flow who | grep imap | wc -l`;
$connectedpop3 = `$DOVEADM -f flow who | grep pop3 | wc -l`;
$connectionsimap = `$DOVEADM -f flow who -1 | grep imap | wc -l`;
$connectionspop3 = `$DOVEADM -f flow who -1 | grep pop3 | wc -l`;
#trim
$connectedimap =~ s/\s+$//;
$connectedpop3 =~ s/\s+$//;
$connectionsimap =~ s/\s+$//;
$connectionspop3 =~ s/\s+$//;
$connected = $connectedimap + $connectedpop3;
$connections = $connectionsimap + $connectionspop3;
my ($pos) = restore_state();
$startsize = (stat $logfile)[7];
if (!defined $pos) {
# Initial run.
$pos = $startsize;
}
if ($startsize < $pos) {
# Log rotated
parseDovecotfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
$pos = 0;
}
parseDovecotfile ($logfile, $pos, $startsize);
$pos = $startsize;
save_state($pos);
print "multigraph dovecot_connections\n";
print "connections.value $connections\n";
print "connectionsimap.value $connectionsimap\n";
print "connectionspop3.value $connectionspop3\n";
print "multigraph dovecot_connected\n";
print "connected.value $connected\n";
print "connectedimap.value $connectedimap\n";
print "connectedpop3.value $connectedpop3\n";
print "multigraph dovecot_logins\n";
print "login.value $login\n";
print "pop3login.value $pop3login\n";
print "imaplogin.value $imaplogin\n";
print "tls.value $tls\n";
print "ssl.value $ssl\n";
print "aborted.value $aborted\n";
sub parseDovecotfile {
my ($fname, $start, $stop) = @_;
open (logf, $fname) or exit 3;
seek (logf, $start, 0) or exit 2;
while (tell (logf) < $stop) {
my $line =<logf>;
chomp ($line);
if ( $dovelogfile == 0 and $line !~ m/dovecot/) { next; }
else {
if ($line =~ m/Aborted/) {
$aborted++;
} elsif ($line =~ m/Login:/) {
$login++;
if ( $line =~ m/TLS/) {
$tls++;
} elsif ($line =~ m/SSL/) {
$ssl++;
}
if ( $line =~ m/pop3-login:/) {
$pop3login++;
} elsif ($line =~ m/imap-login:/) {
$imaplogin++;
}
}
}
}
close(logf);
}
# vim:syntax=perl

View file

@ -0,0 +1,135 @@
#!/bin/bash
: <<=cut
=head1 NAME
dovecot_stats_ - Munin plugin to display statistics for the dovecot mail server
=head1 CONFIGURATION
This plugin must be run with permissions to run "doveadm". That usually means root, but to test, run the following as any user:
doveadm who
If you get a permission denied message, check the permissions on the socket mentioned in the error line.
=head1 MAGIC MARKERS
#%# family=contrib
#%# capability=autoconf suggest
=head1 AUTHOR
Paul Saunders <darac+munin@darac.org.uk>
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
is_multigraph
if [[ "$1" == "autoconf" ]]; then
if [[ -x /usr/bin/doveadm ]]; then
echo yes
else
echo no
fi
exit 0
fi
if [[ "$1" == "suggest" ]]; then
doveadm stats dump domain|awk 'NR!=1 {print $1}'
exit 0
fi
domain=$(basename $0)
domain=${domain#dovecot_stats_}
if [[ -z $domain ]]; then
exit 1
fi
if [[ "$1" == "config" ]]; then
cat <<EOF
multigraph dovecot_cpu_${domain//\./_}
graph_title Dovecot CPU Usage for $domain
graph_vlabel Seconds
graph_category mail
user_cpu.label User CPU
user_cpu.type DERIVE
user_cpu.min 0
user_cpu.cdef user_cpu,1000000,/
sys_cpu.label System CPU
sys_cpu.type DERIVE
sys_cpu.min 0
sys_cpu.cdef sys_cpu,1000000,/
multigraph dovecot_system_${domain//\./_}
graph_title Dovecot System Usage for $domain
graph_category mail
min_faults.label Minor page faults
min_faults.type DERIVE
min_faults.min 0
maj_faults.label Major page faults
maj_faults.type DERIVE
maj_faults.min 0
vol_cs.label Voluntary context switches
vol_cs.type DERIVE
vol_cs.min 0
invol_cs.label Involuntary context switches
invol_cs.type DERIVE
invol_cs.min 0
read_count.label read() syscalls
read_count.type DERIVE
read_count.min 0
write_count.label write() syscalls
write_count.type DERIVE
write_count.min 0
multigraph dovecot_mail_${domain//\./_}
graph_title Dovecot Mail Access for $domain
graph_category mail
num_logins.label Logins
num_logins.type DERIVE
num_logins.min 0
num_cmds.label Commands
num_cmds.type DERIVE
num_cmds.min 0
mail_lookup_path.label Path Lookups
mail_lookup_path.type DERIVE
mail_lookup_path.min 0
mail_lookup_attr.label Attr lookups
mail_lookup_attr.type DERIVE
mail_lookup_attr.min 0
mail_read_count.label Messages read
mail_read_count.type DERIVE
mail_read_count.min 0
mail_cache_hits.label Cache hits
mail_cache_hits.type DERIVE
mail_cache_hits.min 0
EOF
exit 0
fi
# Fetch data
# Gawk script cadged from http://awk.info/?JanisP
doveadm stats dump domain domain=$domain | gawk -F\\t -v cols="user_cpu sys_cpu min_faults maj_faults vol_cs invol_cs read_count write_count num_logins num_cmds mail_lookup_path mail_lookup_attr mail_read_count mail_cache_hits " -v domain=${domain//\./_} '
BEGIN {
n=split(cols,col," ")
for (i=1; i<=n; i++) s[col[i]]=i
}
NR==1 {
for (f=1;f<=NF; f++)
if ($f in s) c[s[$f]]=f
next
}
{ for (f=1; f<=n; f++) {
if (col[f] == "user_cpu") printf ("\nmultigraph dovecot_cpu_%s\n", domain)
if (col[f] == "min_faults") printf ("\nmultigraph dovecot_system_%s\n", domain)
if (col[f] == "num_logins") printf ("\nmultigraph dovecot_mail_%s\n", domain)
if (col[f] == "user_cpu" || col[f] == "sys_cpu")
printf("%s.value %d\n",col[f],$c[f] * 1000000)
else
printf("%s.value %d\n",col[f],$c[f])
}
}
'