Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add socket support for memcached #891

Merged
merged 2 commits into from
May 20, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions checks.d/mcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add that.
This function is used to read from a deprecated configuration format (in datadog.conf)
Can you remove that ?

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)
Expand Down