-
Notifications
You must be signed in to change notification settings - Fork 814
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
[redis] new post 2.8 replication metrics #1350
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,10 @@ | |
# 3rd party | ||
import redis | ||
|
||
|
||
class Redis(AgentCheck): | ||
db_key_pattern = re.compile(r'^db\d+') | ||
slave_key_pattern = re.compile(r'^slave\d+') | ||
subkeys = ['keys', 'expires'] | ||
|
||
SOURCE_TYPE_NAME = 'redis' | ||
|
@@ -63,7 +65,9 @@ class Redis(AgentCheck): | |
'master_last_io_seconds_ago': 'redis.replication.last_io_seconds_ago', | ||
'master_sync_in_progress': 'redis.replication.sync', | ||
'master_sync_left_bytes': 'redis.replication.sync_left_bytes', | ||
|
||
'repl_backlog_histlen': 'redis.replication.backlog_histlen', | ||
'master_repl_offset': 'redis.replication.master_repl_offset', | ||
'slave_repl_offset': 'redis.replication.slave_repl_offset', | ||
} | ||
|
||
RATE_KEYS = { | ||
|
@@ -109,7 +113,7 @@ def _get_conn(self, instance): | |
|
||
# Only send useful parameters to the redis client constructor | ||
list_params = ['host', 'port', 'db', 'password', 'socket_timeout', | ||
'connection_pool', 'charset', 'errors', 'unix_socket_path'] | ||
'connection_pool', 'charset', 'errors', 'unix_socket_path'] | ||
|
||
# Set a default timeout (in seconds) if no timeout is specified in the instance config | ||
instance['socket_timeout'] = instance.get('socket_timeout', 5) | ||
|
@@ -130,7 +134,7 @@ def _check_db(self, instance, custom_tags=None): | |
if 'unix_socket_path' in instance: | ||
tags_to_add = ["unix_socket_path:%s" % instance.get("unix_socket_path")] | ||
else: | ||
tags_to_add = ["redis_host:%s" % instance.get('host'), "redis_port:%s" % instance.get('port')] | ||
tags_to_add = ["redis_host:%s" % instance.get('host'), "redis_port:%s" % instance.get('port')] | ||
|
||
if instance.get('db') is not None: | ||
tags_to_add.append("db:%s" % instance.get('db')) | ||
|
@@ -215,8 +219,23 @@ def _check_db(self, instance, custom_tags=None): | |
self.warning("{0} key not found in redis".format(key)) | ||
self.gauge('redis.key.length', 0, tags=key_tags) | ||
|
||
# Save the replication delay for each slave | ||
for key in info: | ||
if self.slave_key_pattern.match(key) and isinstance(info[key], dict): | ||
slave_offset = info[key].get('offset') | ||
master_offset = info.get('master_repl_offset') | ||
if slave_offset and master_offset and master_offset - slave_offset >= 0: | ||
delay = master_offset - slave_offset | ||
# Add id, ip, and port tags for the slave | ||
slave_tags = tags[:] | ||
for slave_tag in ('ip', 'port'): | ||
if slave_tag in info[key]: | ||
slave_tags.append('slave_{0}:{1}'.format(slave_tag, info[key][slave_tag])) | ||
slave_tags.append('slave_id:%s' % key.lstrip('slave')) | ||
self.gauge('redis.replication.delay', delay, tags=slave_tags) | ||
|
||
def check(self, instance): | ||
if (not "host" in instance or not "port" in instance) and not "unix_socket_path" in instance: | ||
if ("host" not in instance or "port" not in instance) and "unix_socket_path" not in instance: | ||
raise Exception("You must specify a host/port couple or a unix_socket_path") | ||
custom_tags = instance.get('tags', []) | ||
self._check_db(instance,custom_tags) | ||
self._check_db(instance, custom_tags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍰 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that's exactly what we want, see https://gist.github.com/LeoCavaille/801f5bb9288a94ca8d94
Especially the 4th example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LeoCavaille I only moved the "not" keywords to the right place, that didn't change the behavior, which I think is what we want.
As long as there's a socket_path we're good, if there is no socket path, there must be a host and a port. We probably don't want to raise an exception if a user switch from a host:port couple to a socket and forget to remove the host from the config.
See https://github.com/DataDog/dd-agent/blob/haissam/redis-repl-metrics/checks.d/redisdb.py#L103-L107 for the use case.