From ae4ca6eb9681b79c726705bb44daed3e32beafe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Cavaill=C3=A9?= Date: Mon, 26 May 2014 13:04:14 -0400 Subject: [PATCH 1/2] Implements #945: monitor Redis key lengths Using the 'keys' parameter with a list of key names (e.g. 'testkey') in one Redis instance adds a metric 'redis.key.length' where list lengths are reported using the LLEN command and they are tagged with their names (e.g. tag 'key:testkey'). --- checks.d/redisdb.py | 10 ++++++++++ conf.d/redisdb.yaml.example | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/checks.d/redisdb.py b/checks.d/redisdb.py index c926f52059..ac34736e7f 100644 --- a/checks.d/redisdb.py +++ b/checks.d/redisdb.py @@ -177,6 +177,16 @@ def _check_db(self, instance, custom_tags=None): self.rate('redis.net.commands', info['total_commands_processed'], tags=tags) + # Check some key lengths if asked + if instance.get('keys') is not None: + l_tags = list(tags) + for key in instance.get('keys'): + if conn.exists(key): + key_tags = l_tags + ["key:" + key] + self.gauge("redis.key.length", conn.llen(key), tags=key_tags) + else: + self.warning("{0} key not found in redis".format(key)) + def check(self, instance): try: import redis diff --git a/conf.d/redisdb.yaml.example b/conf.d/redisdb.yaml.example index ab6ac3a28a..6f11d7f570 100644 --- a/conf.d/redisdb.yaml.example +++ b/conf.d/redisdb.yaml.example @@ -7,4 +7,7 @@ instances: # password: mypassword # tags: # - optional_tag1 -# - optional_tag2 \ No newline at end of file +# - optional_tag2 +# keys: # check the length of these keys +# - key1 +# - key2 \ No newline at end of file From a6a3bfdb30c66cf82a63070d45d8908c857b641a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Cavaill=C3=A9?= Date: Fri, 6 Jun 2014 13:38:53 -0400 Subject: [PATCH 2/2] Checks that keys are entered as a list in config --- checks.d/redisdb.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/checks.d/redisdb.py b/checks.d/redisdb.py index ac34736e7f..c3e7772922 100644 --- a/checks.d/redisdb.py +++ b/checks.d/redisdb.py @@ -178,9 +178,12 @@ def _check_db(self, instance, custom_tags=None): tags=tags) # Check some key lengths if asked - if instance.get('keys') is not None: + key_list = instance.get('keys') + if not isinstance(key_list, list) or len(key_list) == 0: + self.warning("keys in redis configuration is either not a list or empty") + else: l_tags = list(tags) - for key in instance.get('keys'): + for key in key_list: if conn.exists(key): key_tags = l_tags + ["key:" + key] self.gauge("redis.key.length", conn.llen(key), tags=key_tags)