Skip to content

Commit

Permalink
Merge pull request #891 from mike-lerch/master
Browse files Browse the repository at this point in the history
add socket support for memcached
  • Loading branch information
remh committed May 20, 2014
2 parents 6780b3f + 5bb267d commit 4fb1db1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions checks.d/mcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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
Expand Down Expand Up @@ -162,9 +162,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
Expand All @@ -178,7 +179,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)
Expand Down

0 comments on commit 4fb1db1

Please sign in to comment.