@cryptotaxi247 / netdata-1 / commits / f8addf87d

dovecot support

paulfantom committed Aug 3, 2016 at 20:08 UTC f8addf87d83e43a781e57f517b493a783af2169d
4 files changed +218
conf.d/Makefile.am
+1
@@ -22,6 +22,7 @@ dist_pythonconfig_DATA = \
22 python.d/apache.conf \
23 python.d/apache_cache.conf \
24 python.d/cpufreq.conf \
25 + python.d/dovecot.conf \
26 python.d/example.conf \
27 python.d/exim.conf \
28 python.d/hddtemp.conf \
conf.d/python.d/dovecot.conf new
+89
@@ -0,0 +1,89 @@
1 +# netdata python.d.plugin configuration for dovecot
2 +#
3 +# This file is in YaML format. Generally the format is:
4 +#
5 +# name: value
6 +#
7 +# There are 2 sections:
8 +# - global variables
9 +# - one or more JOBS
10 +#
11 +# JOBS allow you to collect values from multiple sources.
12 +# Each source will have its own set of charts.
13 +#
14 +# JOB parameters have to be indented (using spaces only, example below).
15 +
16 +# ----------------------------------------------------------------------
17 +# Global Variables
18 +# These variables set the defaults for all JOBs, however each JOB
19 +# may define its own, overriding the defaults.
20 +
21 +# update_every sets the default data collection frequency.
22 +# If unset, the python.d.plugin default is used.
23 +# update_every: 1
24 +
25 +# priority controls the order of charts at the netdata dashboard.
26 +# Lower numbers move the charts towards the top of the page.
27 +# If unset, the default for python.d.plugin is used.
28 +# priority: 60000
29 +
30 +# retries sets the number of retries to be made in case of failures.
31 +# If unset, the default for python.d.plugin is used.
32 +# Attempts to restore the service are made once every update_every
33 +# and only if the module has collected values in the past.
34 +# retries: 5
35 +
36 +# ----------------------------------------------------------------------
37 +# JOBS (data collection sources)
38 +#
39 +# The default JOBS share the same *name*. JOBS with the same name
40 +# are mutually exclusive. Only one of them will be allowed running at
41 +# any time. This allows autodetection to try several alternatives and
42 +# pick the one that works.
43 +#
44 +# Any number of jobs is supported.
45 +#
46 +# All python.d.plugin JOBS (for all its modules) support a set of
47 +# predefined parameters. These are:
48 +#
49 +# job_name:
50 +# name: myname # the JOB's name as it will appear at the
51 +# # dashboard (by default is the job_name)
52 +# # JOBs sharing a name are mutually exclusive
53 +# update_every: 1 # the JOB's data collection frequency
54 +# priority: 60000 # the JOB's order on the dashboard
55 +# retries: 5 # the JOB's number of restoration attempts
56 +#
57 +# Additionally to the above, dovecot also supports the following:
58 +#
59 +# socket: 'path/to/dovecot/stats'
60 +#
61 +# or
62 +# host: 'IP or HOSTNAME' # the host to connect to
63 +# port: PORT # the port to connect to
64 +#
65 +#
66 +
67 +# ----------------------------------------------------------------------
68 +# AUTO-DETECTION JOBS
69 +# only one of them will run (they have the same name)
70 +
71 +localhost:
72 + name : 'local'
73 + host : 'localhost'
74 + port : 24242
75 +
76 +localipv4:
77 + name : 'local'
78 + host : '127.0.0.1'
79 + port : 24242
80 +
81 +localipv6:
82 + name : 'local'
83 + host : '::1'
84 + port : 24242
85 +
86 +localsocket:
87 + name : 'local'
88 + socket : '/var/run/dovecot/stats'
89 +
python.d/Makefile.am
+1
@@ -11,6 +11,7 @@ dist_python_SCRIPTS = \
11 apache.chart.py \
12 apache_cache.chart.py \
13 cpufreq.chart.py \
14 + dovecot.chart.py \
15 example.chart.py \
16 exim.chart.py \
17 hddtemp.chart.py \
python.d/dovecot.chart.py new
+127
@@ -0,0 +1,127 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: dovecot netdata python.d module
3 +# Author: Pawel Krupa (paulfantom)
4 +
5 +from base import SocketService
6 +
7 +# default module values (can be overridden per job in `config`)
8 +# update_every = 2
9 +priority = 60000
10 +retries = 60
11 +
12 +# charts order (can be overridden if you want less charts, or different order)
13 +ORDER = ['sessions', 'commands',
14 + 'faults',
15 + 'context_switches',
16 + 'disk', 'bytes', 'syscalls',
17 + 'lookup', 'cache',
18 + 'auth', 'auth_cache']
19 +
20 +CHARTS = {
21 + 'sessions': {
22 + 'options': [None, "logins and sessions", 'number', 'IMAP', 'dovecot.imap', 'line'],
23 + 'lines': [
24 + ['num_logins', 'logins', 'absolute'],
25 + ['num_connected_sessions', 'active sessions', 'absolute']
26 + ]},
27 + 'commands': {
28 + 'options': [None, "commands", "commands", 'IMAP', 'dovecot.imap', 'line'],
29 + 'lines': [
30 + ['num_cmds', 'commands', 'absolute']
31 + ]},
32 + 'faults': {
33 + 'options': [None, "faults", "faults", 'Faults', 'dovecot.faults', 'line'],
34 + 'lines': [
35 + ['min_faults', 'minor', 'absolute'],
36 + ['maj_faults', 'major', 'absolute']
37 + ]},
38 + 'context_switches': {
39 + 'options': [None, "context switches", '', 'Context Switches', 'dovecot.context_switches', 'line'],
40 + 'lines': [
41 + ['vol_cs', 'volountary', 'absolute'],
42 + ['invol_cs', 'involountary', 'absolute']
43 + ]},
44 + 'disk': {
45 + 'options': [None, "disk", 'bytes/s', 'Reads and Writes', 'dovecot.read_write', 'line'],
46 + 'lines': [
47 + ['disk_input', 'read', 'incremental'],
48 + ['disk_output', 'write', 'incremental']
49 + ]},
50 + 'bytes': {
51 + 'options': [None, "bytes", 'bytes/s', 'Reads and Writes', 'dovecot.read_write', 'line'],
52 + 'lines': [
53 + ['read_bytes', 'read', 'incremental'],
54 + ['write_bytes', 'write', 'incremental']
55 + ]},
56 + 'syscalls': {
57 + 'options': [None, "number of syscalls", 'syscalls/s', 'Reads and Writes', 'dovecot.read_write', 'line'],
58 + 'lines': [
59 + ['read_count', 'read', 'incremental'],
60 + ['write_count', 'write', 'incremental']
61 + ]},
62 + 'lookup': {
63 + 'options': [None, "lookups", 'number/s', 'Mail', 'dovecot.mail', 'line'],
64 + 'lines': [
65 + ['mail_lookup_path', 'path', 'incremental'],
66 + ['mail_lookup_attr', 'attr', 'incremental']
67 + ]},
68 + 'cache': {
69 + 'options': [None, "hits", 'hits/s', 'Mail', 'dovecot.mail', 'line'],
70 + 'lines': [
71 + ['mail_cache_hits', 'hits', 'incremental']
72 + ]},
73 + 'auth': {
74 + 'options': [None, "attempts", 'attempts', 'Authentication', 'dovecot.auth', 'stacked'],
75 + 'lines': [
76 + ['auth_successes', 'success', 'absolute'],
77 + ['auth_failures', 'failure', 'absolute']
78 + ]},
79 + 'auth_cache': {
80 + 'options': [None, "cache", 'number', 'Authentication', 'dovecot.auth', 'stacked'],
81 + 'lines': [
82 + ['auth_cache_hits', 'hit', 'absolute'],
83 + ['auth_cache_misses', 'miss', 'absolute']
84 + ]}
85 +}
86 +
87 +
88 +class Service(SocketService):
89 + def __init__(self, configuration=None, name=None):
90 + SocketService.__init__(self, configuration=configuration, name=name)
91 + self.request = "EXPORT\tglobal\r\n"
92 + self.host = None # localhost
93 + self.port = None # 24242
94 + # self._keep_alive = True
95 + self.unix_socket = "/var/run/dovecot/stats"
96 + self.order = ORDER
97 + self.definitions = CHARTS
98 +
99 + def _get_data(self):
100 + """
101 + Format data received from socket
102 + :return: dict
103 + """
104 + try:
105 + raw = self._get_raw_data()
106 + except (ValueError, AttributeError):
107 + return None
108 +
109 + data = raw.split('\n')[:2]
110 + desc = data[0].split('\t')
111 + vals = data[1].split('\t')
112 + # ret = dict(zip(desc, vals))
113 + ret = {}
114 + for i in range(len(desc)):
115 + try:
116 + #d = str(desc[i])
117 + #if d in ('user_cpu', 'sys_cpu', 'clock_time'):
118 + # val = float(vals[i])
119 + #else:
120 + # val = int(vals[i])
121 + #ret[d] = val
122 + ret[str(desc[i])] = int(vals[i])
123 + except ValueError:
124 + pass
125 + if len(ret) == 0:
126 + return None
127 + return ret