Skip to content

Commit

Permalink
Merge pull request #179 from mkralka/master
Browse files Browse the repository at this point in the history
Fix connection leak in redis-stats collector
  • Loading branch information
johann8384 committed Nov 11, 2014
2 parents 9f807e2 + 0b9ddc6 commit a34bcc2
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions collectors/0/redis-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,24 @@ def print_stat(metric, value, tags=""):

# connect to the instance and attempt to gather info
r = redis.Redis(host="127.0.0.1", port=port)
info = r.info()
for key in KEYS:
if key in info:
print_stat(key, info[key], tags)

# per database metrics
for db in filter(dbre.match, info.keys()):
for db_metric in info[db].keys():
print_stat(db_metric, info[db][db_metric], "%s db=%s" % (tags, db))

# get some instant latency information
# TODO: might be nice to get 95th, 99th, etc here?
start_time = time.time()
r.ping()
print_stat("latency", time.time() - start_time, tags)
try:
info = r.info()
for key in KEYS:
if key in info:
print_stat(key, info[key], tags)

# per database metrics
for db in filter(dbre.match, info.keys()):
for db_metric in info[db].keys():
print_stat(db_metric, info[db][db_metric], "%s db=%s" % (tags, db))

# get some instant latency information
# TODO: might be nice to get 95th, 99th, etc here?
start_time = time.time()
r.ping()
print_stat("latency", time.time() - start_time, tags)
finally:
r.connection_pool.disconnect()

sys.stdout.flush()
time.sleep(interval)
Expand Down

0 comments on commit a34bcc2

Please sign in to comment.