From 4143cd6d4f108b1798454b476c7c4caf4ec22a80 Mon Sep 17 00:00:00 2001 From: Mike Lerch Date: Tue, 1 Apr 2014 13:00:25 -0700 Subject: [PATCH 1/2] add socket support for memcached; include socket: in the yaml instead of server: and port: --- checks.d/mcache.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/checks.d/mcache.py b/checks.d/mcache.py index 4732212b22..d73c1b18f2 100644 --- a/checks.d/mcache.py +++ b/checks.d/mcache.py @@ -98,7 +98,7 @@ def _get_metrics(self, server, port, tags, memcache): mc = None # client try: self.log.debug("Connecting to %s:%s tags:%s", server, port, tags) - mc = memcache.Client(["%s:%d" % (server, port)]) + mc = memcache.Client(["%s:%s" % (server, port)]) raw_stats = mc.get_stats() assert len(raw_stats) == 1 and len(raw_stats[0]) == 2, "Malformed response: %s" % raw_stats @@ -154,9 +154,10 @@ def _get_metrics(self, server, port, tags, memcache): del mc def check(self, instance): + socket = instance.get('socket', None) server = instance.get('url', None) - if not server: - raise Exception("Missing or null 'url' in mcache config") + if not server and not socket: + raise Exception("Missing or null 'url' and 'socket' in mcache config") try: import memcache @@ -170,7 +171,11 @@ def check(self, instance): except Exception: pass - port = int(instance.get('port', self.DEFAULT_PORT)) + if socket: + server = 'unix' + port = socket + else: + port = int(instance.get('port', self.DEFAULT_PORT)) tags = instance.get('tags', None) self._get_metrics(server, port, tags, memcache) @@ -180,12 +185,14 @@ def parse_agent_config(agentConfig): all_instances = [] # Load the conf according to the old schema + memcache_socket = agentConfig.get("memcache_socket", None) memcache_url = agentConfig.get("memcache_server", None) memcache_port = agentConfig.get("memcache_port", Memcache.DEFAULT_PORT) - if memcache_url is not None: + if memcache_url is not None or memcache_socket is not None: instance = { 'url': memcache_url, 'port': memcache_port, + 'socket': memcache_socket, 'tags': ["instance:%s_%s" % (memcache_url, memcache_port)] } all_instances.append(instance) From 5bb267da625a24af80c615b33fa1b8bdac268b8e Mon Sep 17 00:00:00 2001 From: Mike Lerch Date: Mon, 14 Apr 2014 17:09:26 -0700 Subject: [PATCH 2/2] don't add socket support to old config method --- checks.d/mcache.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/checks.d/mcache.py b/checks.d/mcache.py index d73c1b18f2..0c82b03f41 100644 --- a/checks.d/mcache.py +++ b/checks.d/mcache.py @@ -185,14 +185,12 @@ def parse_agent_config(agentConfig): all_instances = [] # Load the conf according to the old schema - memcache_socket = agentConfig.get("memcache_socket", None) memcache_url = agentConfig.get("memcache_server", None) memcache_port = agentConfig.get("memcache_port", Memcache.DEFAULT_PORT) - if memcache_url is not None or memcache_socket is not None: + if memcache_url is not None: instance = { 'url': memcache_url, 'port': memcache_port, - 'socket': memcache_socket, 'tags': ["instance:%s_%s" % (memcache_url, memcache_port)] } all_instances.append(instance)