Skip to content

Commit

Permalink
Fix comments as per reviews
Browse files Browse the repository at this point in the history
Typos and more defined test
  • Loading branch information
remh committed Feb 27, 2015
1 parent 5e8e943 commit 6f52aee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions checks.d/redisdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import redis

DEFAULT_MAX_SLOW_ENTRIES = 128
MAX_SLOW_ENTRIES_KEY = "slowlog-max-len"

class Redis(AgentCheck):
db_key_pattern = re.compile(r'^db\d+')
Expand Down Expand Up @@ -253,17 +254,17 @@ def _check_slowlog(self, instance, custom_tags):
"""

max_slow_entries = "slowlog-max-len"

conn = self._get_conn(instance)

tags, tags_to_add = self._get_tags(custom_tags, instance)

if not instance.get(max_slow_entries):
max_slow_entries = int(conn.config_get(max_slow_entries)[max_slow_entries])
if not instance.get(MAX_SLOW_ENTRIES_KEY):
max_slow_entries = int(conn.config_get(MAX_SLOW_ENTRIES_KEY)[MAX_SLOW_ENTRIES_KEY])
if max_slow_entries > DEFAULT_MAX_SLOW_ENTRIES:
self.warning("Redis {0} is higher than {1}. Defaulting to {1}."\
"If you need a higher value, please set {0} in your check config"\
.format(max_slow_entries, DEFAULT_MAX_SLOW_ENTRIES))
.format(MAX_SLOW_ENTRIES_KEY, DEFAULT_MAX_SLOW_ENTRIES))
max_slow_entries = DEFAULT_MAX_SLOW_ENTRIES
else:
max_slow_entries = int(instance.get(max_slow_entries))
Expand Down
9 changes: 5 additions & 4 deletions conf.d/redisdb.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ instances:
#
# warn_on_missing_keys: True

# Max number of entries to fetch from the sloq query log
# By default, the check wil read this value from the redis config
# But if it's too high, it will default to 128
# Max number of entries to fetch from the slow query log
# By default, the check will read this value from the redis config
# If it's above 128, it will default to 128 due to potential increased latency
# to retrieve more than 128 slowlog entries every 15 seconds
# If you need to get more entries from the slow query logs
# set the value here.
# Warning: It maybe impact the performances of your redis instance
# Warning: It may impact the performance of your redis instance
# slowlog-max-len: 128
3 changes: 2 additions & 1 deletion tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def test_slowlog(self):
self.run_check({"init_config": {}, "instances": [instance]})

assert self.metrics, "No metrics returned"
self.assertMetric("redis.slowlog.micros.max")
self.assertMetric("redis.slowlog.micros.max", tags=["command:SORT",
"redis_host:localhost", "redis_port:{0}".format(port)])


def _sort_metrics(self, metrics):
Expand Down

0 comments on commit 6f52aee

Please sign in to comment.