summaryrefslogtreecommitdiffstats
path: root/roles/common/files/usr/local/share/munin/plugins/dovecot_stats_
blob: 7f0f51a9e8bd27f4ada78e4c49f43b13dd5b3e85 (plain)
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
#!/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 dovecot
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 dovecot
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 dovecot
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])
      }
    }
'