]> arthur.barton.de Git - netdata.git/commitdiff
add memcached support
authorpaulfantom <paulfantom@gmail.com>
Tue, 2 Aug 2016 18:36:00 +0000 (20:36 +0200)
committerpaulfantom <paulfantom@gmail.com>
Tue, 2 Aug 2016 18:36:00 +0000 (20:36 +0200)
conf.d/Makefile.am
conf.d/python.d/memcached.conf [new file with mode: 0644]
python.d/Makefile.am
python.d/memcached.chart.py [new file with mode: 0644]

index 20fc706230797f4e10f01e8967670b508fc683aa..84b6c47a1ab1a06601352661b05ded1e53fd7b27 100644 (file)
@@ -25,6 +25,7 @@ dist_pythonconfig_DATA = \
        python.d/example.conf \
        python.d/exim.conf \
        python.d/hddtemp.conf \
+       python.d/memcached.conf \
        python.d/mysql.conf \
        python.d/nginx.conf \
        python.d/phpfpm.conf \
diff --git a/conf.d/python.d/memcached.conf b/conf.d/python.d/memcached.conf
new file mode 100644 (file)
index 0000000..f1723dc
--- /dev/null
@@ -0,0 +1,85 @@
+# netdata python.d.plugin configuration for memcached
+#
+# This file is in YaML format. Generally the format is:
+#
+# name: value
+#
+# There are 2 sections:
+#  - global variables
+#  - one or more JOBS
+#
+# JOBS allow you to collect values from multiple sources.
+# Each source will have its own set of charts.
+#
+# JOB parameters have to be indented (using spaces only, example below).
+
+# ----------------------------------------------------------------------
+# Global Variables
+# These variables set the defaults for all JOBs, however each JOB
+# may define its own, overriding the defaults.
+
+# update_every sets the default data collection frequency.
+# If unset, the python.d.plugin default is used.
+# update_every: 1
+
+# priority controls the order of charts at the netdata dashboard.
+# Lower numbers move the charts towards the top of the page.
+# If unset, the default for python.d.plugin is used.
+# priority: 60000
+
+# retries sets the number of retries to be made in case of failures.
+# If unset, the default for python.d.plugin is used.
+# Attempts to restore the service are made once every update_every
+# and only if the module has collected values in the past.
+# retries: 5
+
+# ----------------------------------------------------------------------
+# JOBS (data collection sources)
+#
+# The default JOBS share the same *name*. JOBS with the same name
+# are mutually exclusive. Only one of them will be allowed running at
+# any time. This allows autodetection to try several alternatives and
+# pick the one that works.
+#
+# Any number of jobs is supported.
+#
+# All python.d.plugin JOBS (for all its modules) support a set of
+# predefined parameters. These are:
+#
+# job_name:
+#     name: myname     # the JOB's name as it will appear at the
+#                      # dashboard (by default is the job_name)
+#                      # JOBs sharing a name are mutually exclusive
+#     update_every: 1  # the JOB's data collection frequency
+#     priority: 60000  # the JOB's order on the dashboard
+#     retries: 5       # the JOB's number of restoration attempts
+#
+# Additionally to the above, memcached also supports the following:
+#
+#     socket: 'path/to/memcached.sock'
+#
+#  or
+#     host: 'IP or HOSTNAME' # the host to connect to
+#     port: PORT             # the port to connect to
+#
+#
+
+# ----------------------------------------------------------------------
+# AUTO-DETECTION JOBS
+# only one of them will run (they have the same name)
+
+localhost:
+  name     : 'local'
+  host     : 'localhost'
+  port     : 11211
+
+localipv4:
+  name     : 'local'
+  host     : '127.0.0.1'
+  port     : 11211
+
+localipv6:
+  name     : 'local'
+  host     : '::1'
+  port     : 11211
+
index cdb19d2ddc7d0d4f6999d42481f3786ebf628c24..51ebad096cbc181bcd5837edfd69452fdee0549b 100644 (file)
@@ -14,6 +14,7 @@ dist_python_SCRIPTS = \
        example.chart.py \
        exim.chart.py \
        hddtemp.chart.py \
+       memcached.chart.py \
        mysql.chart.py \
        nginx.chart.py \
        phpfpm.chart.py \
diff --git a/python.d/memcached.chart.py b/python.d/memcached.chart.py
new file mode 100644 (file)
index 0000000..12e0fb9
--- /dev/null
@@ -0,0 +1,160 @@
+# -*- coding: utf-8 -*-
+# Description: memcached 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 = 60
+
+# default job configuration (overridden by python.d.plugin)
+# config = {'local': {
+#             'update_every': update_every,
+#             'retries': retries,
+#             'priority': priority,
+#             'host': 'localhost',
+#             'port': 11211,
+#             'unix_socket': None
+#          }}
+
+ORDER = ['net', 'connections', 'items', 'evicted_reclaimed', 'get', 'get_rate', 'set_rate', 'delete', 'cas', 'increment', 'decrement', 'touch', 'touch_rate']
+
+CHARTS = {
+    'net': {
+        'options': [None, 'Network', 'bytes', 'Network', 'memcached.net', 'line'],
+        'lines': [
+            ['bytes_read', 'read', 'absolute'],
+            ['bytes_written', 'written', 'absolute']
+        ]},
+    'connections': {
+        'options': [None, 'Connections', 'connections', 'Cluster', 'memcached.cluster', 'line'],
+        'lines': [
+            ['curr_connections', 'current', 'absolute'],
+            ['rejected_connections', 'rejected', 'absolute'],
+            ['total_connections', 'total', 'absolute']
+        ]},
+    'items': {
+        'options': [None, 'Items', 'items', 'Cluster', 'memcached.cluster', 'line'],
+        'lines': [
+            ['curr_items', 'current', 'absolute'],
+            ['total_items', 'total', 'absolute']
+        ]},
+    'evicted_reclaimed': {
+        'options': [None, 'Items', 'items', 'Evicted & Reclaimed', 'memcached.evicted_reclaimed', 'line'],
+        'lines': [
+            ['evictions', 'evicted', 'absolute'],
+            ['reclaimed', 'reclaimed', 'absolute']
+        ]},
+    'get': {
+        'options': [None, 'Requests', 'requests', 'GET', 'memcached.get', 'stacked'],
+        'lines': [
+            ['get_hits', 'hits', 'percent-of-absolute-row'],
+            ['get_misses', 'misses', 'percent-of-absolute-row']
+        ]},
+    'get_rate': {
+        'options': [None, 'Rate', 'requests/s', 'GET', 'memcached.get', 'line'],
+        'lines': [
+            ['cmd_get', 'rate', 'incremental']
+        ]},
+    'set_rate': {
+        'options': [None, 'Rate', 'requests/s', 'SET', 'memcached.set', 'line'],
+        'lines': [
+            ['cmd_set', 'rate', 'incremental']
+        ]},
+    'delete': {
+        'options': [None, 'Requests', 'requests', 'DELETE', 'memcached.delete', 'stacked'],
+        'lines': [
+            ['delete_hits', 'hits', 'percent-of-absolute-row'],
+            ['delete_misses', 'misses', 'percent-of-absolute-row'],
+        ]},
+    'cas': {
+        'options': [None, 'Requests', 'requests', 'CAS', 'memcached.cas', 'stacked'],
+        'lines': [
+            ['cas_hits', 'hits', 'percent-of-absolute-row'],
+            ['cas_misses', 'misses', 'percent-of-absolute-row'],
+            ['cas_badval', 'bad value', 'percent-of-absolute-row']
+        ]},
+    'increment': {
+        'options': [None, 'Requests', 'requests', 'Increment', 'memcached.incr', 'stacked'],
+        'lines': [
+            ['incr_hits', 'hits', 'percent-of-absolute-row'],
+            ['incr_misses', 'misses', 'percent-of-absolute-row']
+        ]},
+    'decrement': {
+        'options': [None, 'Requests', 'requests', 'Decrement', 'memcached.decr', 'stacked'],
+        'lines': [
+            ['decr_hits', 'hits', 'percent-of-absolute-row'],
+            ['decr_misses', 'misses', 'percent-of-absolute-row']
+        ]},
+    'touch': {
+        'options': [None, 'Requests', 'requests', 'Touch', 'memcached.touch', 'stacked'],
+        'lines': [
+            ['touch_hits', 'hits', 'percent-of-absolute-row'],
+            ['touch_misses', 'misses', 'percent-of-absolute-row']
+        ]},
+    'touch_rate': {
+        'options': [None, 'Rate', 'requests/s', 'Touch', 'memcached.touch', 'line'],
+        'lines': [
+            ['cmd_touch', 'rate', 'incremental']
+        ]}
+}
+
+
+class Service(SocketService):
+    def __init__(self, configuration=None, name=None):
+        SocketService.__init__(self, configuration=configuration, name=name)
+        self.request = "stats\r\n"
+        self.host = "localhost"
+        self.port = 11211
+        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:
+            self.error("no data received")
+            return None
+        if raw[0].startswith('ERROR'):
+            self.error("Memcached returned ERROR")
+            return None
+        data = {}
+        for line in raw:
+            if line.startswith('STAT'):
+                try:
+                    t = line[5:].split(' ')
+                    data[t[0]] = int(t[1])
+                except (IndexError, ValueError):
+                    pass
+        try:
+            data['hit_rate'] = int((data['keyspace_hits'] / float(data['keyspace_hits'] + data['keyspace_misses'])) * 100)
+        except:
+            data['hit_rate'] = 0
+
+        if len(data) == 0:
+            self.error("received data doesn't have needed records")
+            return None
+        else:
+            return data
+
+    def check(self):
+        """
+        Parse configuration, check if memcached is available
+        :return: boolean
+        """
+        self._parse_config()
+        if self.name == "":
+            self.name = "local"
+        self.chart_name += "_" + self.name
+        data = self._get_data()
+        if data is None:
+            return False
+
+        return True