1 # -*- coding: utf-8 -*-
2 # Description: redis netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
5 from base import SocketService
7 # default module values (can be overridden per job in `config`)
12 # default job configuration (overridden by python.d.plugin)
13 # config = {'local': {
14 # 'update_every': update_every,
16 # 'priority': priority,
17 # 'host': 'localhost',
22 ORDER = ['operations', 'hit_rate', 'memory', 'keys', 'clients', 'slaves']
26 'options': [None, 'Operations', 'operations/s', 'Statistics', 'redis.statistics', 'line'],
28 ['instantaneous_ops_per_sec', None, 'absolute']
31 'options': [None, 'Hit rate', 'percent', 'Statistics', 'redis.statistics', 'line'],
33 ['hit_rate', None, 'absolute']
36 'options': [None, 'Memory utilization', 'bytes', 'Memory', 'redis.memory', 'line'],
38 ['used_memory', None, 'absolute'],
39 ['memory_', None, 'absolute'],
40 ['memory_', None, 'absolute']
43 'options': [None, 'Database keys', 'keys', 'Keys', 'redis.keys', 'line'],
45 # lines are created dynamically in `check()` method
48 'options': [None, 'Clients', 'clients', 'Clients', 'redis.clients', 'line'],
50 ['connected_clients', None, 'absolute'],
51 ['blocked_clients', None, 'absolute']
54 'options': [None, 'Slaves', 'slaves', 'Replication', 'redis.replication', 'line'],
56 ['connected_slaves', None, 'absolute']
61 class Service(SocketService):
62 def __init__(self, configuration=None, name=None):
63 SocketService.__init__(self, configuration=configuration, name=name)
64 self.request = "INFO\r\n"
65 self.host = "localhost"
67 self.unix_socket = None
69 self.definitions = CHARTS
77 raw = self._get_raw_data().split("\n")
78 except AttributeError:
82 if line.startswith(('instantaneous', 'keyspace', 'used_memory', 'connected', 'blocked')):
85 data[t[0]] = int(t[1])
86 except (IndexError, ValueError):
88 elif line.startswith('db'):
89 tmp = line.split(',')[0].replace('keys=', '')
90 record = tmp.split(':')
91 data[record[0]] = int(record[1])
93 data['hit_rate'] = int((data['keyspace_hits'] / (data['keyspace_hits'] + data['keyspace_misses'])) * 100)
101 Parse configuration, check if redis is available, and dynamically create chart lines data
105 data = self._get_data()
107 self.error("No data received")
111 if name.startswith('db'):
112 self.definitions['keys']['lines'].append(data[name, None, 'absolute'])