Skip to content

Commit

Permalink
Add replication metrics in Redis check
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaj committed Feb 5, 2015
1 parent 5701eaf commit 52d68fa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
16 changes: 15 additions & 1 deletion checks.d/redisdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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'
Expand Down Expand Up @@ -63,7 +64,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 = {
Expand Down Expand Up @@ -215,6 +218,17 @@ 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
slave_tags = tags + ['slave_ip:%s' % info[key]['ip']] if 'ip' in info[key] else tags
slave_tags.append('slave_id:%s' % key.lstrip('slave'))
self.gauge('redis.replication.delay.%s' % key, 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:
raise Exception("You must specify a host/port couple or a unix_socket_path")
Expand Down
23 changes: 21 additions & 2 deletions ci/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,27 @@ def redis_rootdir
Rake::Task['ci:common:run_tests'].invoke(this_provides)
end

task :cleanup => ['ci:common:cleanup']
# FIXME: stop redis
task :cleanup => ['ci:common:cleanup'] do
# Shutdown redis
conf_files = ["#{ENV['TRAVIS_BUILD_DIR']}/ci/resources/redis/auth.conf",
"#{ENV['TRAVIS_BUILD_DIR']}/ci/resources/redis/noauth.conf"]
for f in conf_files do
pass, port = nil, nil
File.readlines(f).each do |line|
param = line.split(' ')
if param[0] == 'port'
port = param[1]
elsif param[0] == 'requirepass'
pass = param[1]
end
end
if pass and port
sh %(#{redis_rootdir}/src/redis-cli -p #{port} -a #{pass} SHUTDOWN)
elsif port
sh %(#{redis_rootdir}/src/redis-cli -p #{port} SHUTDOWN)
end
end
end

task :execute do
exception = nil
Expand Down
1 change: 1 addition & 0 deletions ci/resources/redis/auth.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pidfile /tmp/dd-redis-auth.pid
bind 127.0.0.1
port 26379
requirepass datadog-is-devops-best-friend
slaveof 127.0.0.1 16379

0 comments on commit 52d68fa

Please sign in to comment.