]> arthur.barton.de Git - netdata.git/blob - python.d/dovecot.chart.py
fixed context for python.d charts
[netdata.git] / python.d / dovecot.chart.py
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.sessions', '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.commands', '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.disk', '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.bytes', '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.syscalls', 'line'],
58         'lines': [
59             ['read_count', 'read', 'incremental'],
60             ['write_count', 'write', 'incremental']
61         ]},
62     'lookup': {
63         'options': [None, "lookups", 'number/s', 'Mail', 'dovecot.lookup', '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.cache', '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_cache', '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