]> arthur.barton.de Git - netdata.git/blob - python.d/dovecot.chart.py
MySQLService: "queries" finding preference changed (1.module conf 2.module code)
[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', 'logins', 'commands',
14          'faults',
15          'context_switches',
16          'io', 'net', 'syscalls',
17          'lookup', 'cache',
18          'auth', 'auth_cache']
19
20 CHARTS = {
21     'sessions': {
22         'options': [None, "Dovecot Active Sessions", 'number', 'sessions', 'dovecot.sessions', 'line'],
23         'lines': [
24             ['num_connected_sessions', 'active sessions', 'absolute']
25         ]},
26     'logins': {
27         'options': [None, "Dovecot Logins", 'number', 'logins', 'dovecot.logins', 'line'],
28         'lines': [
29             ['num_logins', 'logins', 'absolute']
30         ]},
31     'commands': {
32         'options': [None, "Dovecot Commands", "commands", 'commands', 'dovecot.commands', 'line'],
33         'lines': [
34             ['num_cmds', 'commands', 'absolute']
35         ]},
36     'faults': {
37         'options': [None, "Dovecot Page Faults", "faults", 'page faults', 'dovecot.faults', 'line'],
38         'lines': [
39             ['min_faults', 'minor', 'absolute'],
40             ['maj_faults', 'major', 'absolute']
41         ]},
42     'context_switches': {
43         'options': [None, "Dovecot Context Switches", '', 'context switches', 'dovecot.context_switches', 'line'],
44         'lines': [
45             ['vol_cs', 'volountary', 'absolute'],
46             ['invol_cs', 'involountary', 'absolute']
47         ]},
48     'io': {
49         'options': [None, "Dovecot Disk I/O", 'kilobytes/s', 'disk', 'dovecot.io', 'area'],
50         'lines': [
51             ['disk_input', 'read', 'incremental', 1, 1024],
52             ['disk_output', 'write', 'incremental', -1, 1024]
53         ]},
54     'net': {
55         'options': [None, "Dovecot Network Bandwidth", 'kilobits/s', 'network', 'dovecot.net', 'area'],
56         'lines': [
57             ['read_bytes', 'read', 'incremental', 8, 1024],
58             ['write_bytes', 'write', 'incremental', -8, 1024]
59         ]},
60     'syscalls': {
61         'options': [None, "Dovecot Number of SysCalls", 'syscalls/s', 'system', 'dovecot.syscalls', 'line'],
62         'lines': [
63             ['read_count', 'read', 'incremental'],
64             ['write_count', 'write', 'incremental']
65         ]},
66     'lookup': {
67         'options': [None, "Dovecot Lookups", 'number/s', 'lookups', 'dovecot.lookup', 'stacked'],
68         'lines': [
69             ['mail_lookup_path', 'path', 'incremental'],
70             ['mail_lookup_attr', 'attr', 'incremental']
71         ]},
72     'cache': {
73         'options': [None, "Dovecot Cache Hits", 'hits/s', 'cache', 'dovecot.cache', 'line'],
74         'lines': [
75             ['mail_cache_hits', 'hits', 'incremental']
76         ]},
77     'auth': {
78         'options': [None, "Dovecot Authentications", 'attempts', 'logins', 'dovecot.auth', 'stacked'],
79         'lines': [
80             ['auth_successes', 'ok', 'absolute'],
81             ['auth_failures', 'failed', 'absolute']
82         ]},
83     'auth_cache': {
84         'options': [None, "Dovecot Authentication Cache", 'number', 'cache', 'dovecot.auth_cache', 'stacked'],
85         'lines': [
86             ['auth_cache_hits', 'hit', 'absolute'],
87             ['auth_cache_misses', 'miss', 'absolute']
88         ]}
89 }
90
91
92 class Service(SocketService):
93     def __init__(self, configuration=None, name=None):
94         SocketService.__init__(self, configuration=configuration, name=name)
95         self.request = "EXPORT\tglobal\r\n"
96         self.host = None  # localhost
97         self.port = None  # 24242
98         # self._keep_alive = True
99         self.unix_socket = "/var/run/dovecot/stats"
100         self.order = ORDER
101         self.definitions = CHARTS
102
103     def _get_data(self):
104         """
105         Format data received from socket
106         :return: dict
107         """
108         try:
109             raw = self._get_raw_data()
110         except (ValueError, AttributeError):
111             return None
112
113         if raw is None:
114             self.debug("dovecot returned no data")
115             return None
116
117         data = raw.split('\n')[:2]
118         desc = data[0].split('\t')
119         vals = data[1].split('\t')
120         # ret = dict(zip(desc, vals))
121         ret = {}
122         for i in range(len(desc)):
123             try:
124                 #d = str(desc[i])
125                 #if d in ('user_cpu', 'sys_cpu', 'clock_time'):
126                 #    val = float(vals[i])
127                 #else:
128                 #    val = int(vals[i])
129                 #ret[d] = val
130                 ret[str(desc[i])] = int(vals[i])
131             except ValueError:
132                 pass
133         if len(ret) == 0:
134             return None
135         return ret