diff options
author | paulfantom <paulfantom@gmail.com> | 2016-07-12 16:35:43 +0200 |
---|---|---|
committer | paulfantom <paulfantom@gmail.com> | 2016-07-12 16:35:43 +0200 |
commit | ab209cd429e4b66183a7bf26e127790d7cd85cb3 (patch) | |
tree | 0f514132805a020b27857c411fd70405769a568d /python.d/redis.chart.py | |
parent | 6cda78c2fc4ec8dd3492acbe4b2fed8d42abb6d4 (diff) |
not tested redis module
Diffstat (limited to 'python.d/redis.chart.py')
-rw-r--r-- | python.d/redis.chart.py | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/python.d/redis.chart.py b/python.d/redis.chart.py new file mode 100644 index 0000000000..dac8ffaaa8 --- /dev/null +++ b/python.d/redis.chart.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Description: redis netdata python.d module +# Author: Pawel Krupa (paulfantom) + +from base import SocketService + +# default module values (can be overridden per job in `config`) +#update_every = 2 +priority = 60000 +retries = 5 + +# default job configuration (overridden by python.d.plugin) +# config = {'local': { +# 'update_every': update_every, +# 'retries': retries, +# 'priority': priority, +# 'host': 'localhost', +# 'port': 6379, +# 'unix_socket': None +# }} + +ORDER = ['operations', 'hit_rate', 'memory', 'keys', 'clients', 'slaves'] + +CHARTS = { + 'operations': { + 'options': [None, 'Operations', 'operations/s', 'Statistics', 'redis.statistics', 'line'], + 'lines': [ + ['instantaneous_ops_per_sec', None, 'absolute'] + ]}, + 'hit_rate': { + 'options': [None, 'Hit rate', 'percent', 'Statistics', 'redis.statistics', 'line'], + 'lines': [ + ['hit_rate', None, 'absolute'] + ]}, + 'memory': { + 'options': [None, 'Memory utilization', 'bytes', 'Memory', 'redis.memory', 'line'], + 'lines': [ + ['used_memory', None, 'absolute'], + ['memory_', None, 'absolute'], + ['memory_', None, 'absolute'] + ]}, + 'keys': { + 'options': [None, 'Database keys', 'keys', 'Keys', 'redis.keys', 'line'], + 'lines': [ + # lines are created dynamically in `check()` method + ]}, + 'clients': { + 'options': [None, 'Clients', 'clients', 'Clients', 'redis.clients', 'line'], + 'lines': [ + ['connected_clients', None, 'absolute'], + ['blocked_clients', None, 'absolute'] + ]}, + 'slaves': { + 'options': [None, 'Slaves', 'slaves', 'Replication', 'redis.replication', 'line'], + 'lines': [ + ['connected_slaves', None, 'absolute'] + ]} +} + + +class Service(SocketService): + def __init__(self, configuration=None, name=None): + SocketService.__init__(self, configuration=configuration, name=name) + self.request = "INFO\r\n" + self.host = "localhost" + self.port = 6379 + self.unix_socket = None + self.order = ORDER + self.definitions = CHARTS + + def _get_data(self): + """ + Get data from socket + :return: dict + """ + try: + raw = self._get_raw_data().split("\n") + except AttributeError: + return None + data = {} + for line in raw: + if line.startswith(('instantaneous', 'keyspace', 'used_memory', 'connected', 'blocked')): + try: + t = line.split(':') + data[t[0]] = int(t[1]) + except (IndexError, ValueError): + pass + elif line.startswith('db'): + tmp = line.split(',')[0].replace('keys=', '') + record = tmp.split(':') + data[record[0]] = int(record[1]) + try: + data['hit_rate'] = int((data['keyspace_hits'] / (data['keyspace_hits'] + data['keyspace_misses'])) * 100) + except: + data['hit_rate'] = 0 + + return data + + def check(self): + """ + Parse configuration, check if redis is available, and dynamically create chart lines data + :return: boolean + """ + self._parse_config() + data = self._get_data() + if data is None: + self.error("No data received") + return False + + for name in data: + if name.startswith('db'): + self.definitions['keys']['lines'].append(data[name, None, 'absolute']) + + return True |