Skip to content

Commit

Permalink
Fix flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Stumpf committed Nov 10, 2017
1 parent 7030588 commit fec2aed
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions redis_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CONFIGS = []
REDIS_INFO = {}


def fetch_info(conf):
"""Connect to Redis server and request info"""
try:
Expand Down Expand Up @@ -85,14 +86,15 @@ def fetch_info(conf):
info_dict = parse_info(data.split(linesep))
fp.close()

## monitoring lengths of custom keys
# monitoring lengths of custom keys
key_dict = get_llen_keys(s, conf)
info_dict.update(key_dict)

s.close()

return info_dict


def get_llen_keys(socket, conf):
"""
for each llen_key specified in the config file,
Expand All @@ -105,10 +107,10 @@ def get_llen_keys(socket, conf):
if len(conf['llen_keys']) > 0:
for db, keys in conf['llen_keys'].items():
socket.sendall('select %d\r\n' % db)
status_line = llen_fp.readline() ## +OK
for key in keys:
status_line = llen_fp.readline() # +OK
for key in keys:
socket.sendall('llen %s\r\n' % key)
status_line = llen_fp.readline() ## :VALUE
status_line = llen_fp.readline() # :VALUE
try:
val = int(filter(str.isdigit, status_line))
except ValueError:
Expand All @@ -120,6 +122,7 @@ def get_llen_keys(socket, conf):
llen_fp.close()
return key_dict


def parse_info(info_lines):
"""Parse info response from Redis"""
info = {}
Expand Down Expand Up @@ -245,6 +248,7 @@ def dispatch_value(info, key, type, plugin_instance=None, type_instance=None):
val.meta = {'0': True}
val.dispatch()


def dispatch_llen_key(key_name, key_value, db_index, plugin_instance):
"""
adds dimensions for key value and db_index for
Expand All @@ -265,10 +269,11 @@ def dispatch_llen_key(key_name, key_value, db_index, plugin_instance):
val.meta = {'0': True}
val.dispatch()


def build_dimensions(keyname, db_index):
dim = {'key_name': keyname, 'db_index': db_index}
return _format_dimensions(dim)


def _format_dimensions(dimensions):
"""
Expand All @@ -286,6 +291,7 @@ def _format_dimensions(dimensions):
dim_pairs = ["%s=%s" % (k, v) for k, v in dimensions.iteritems()]
return "[%s]" % (",".join(dim_pairs))


def read_callback():
for conf in CONFIGS:
get_metrics(conf)
Expand Down Expand Up @@ -320,13 +326,13 @@ def get_metrics(conf):
'commands_processed')
else:
dispatch_value(info, key, val, plugin_instance)

for db, keys in conf['llen_keys'].items():
for key in keys:
subkey = "db{0}_llen_{1}".format(db, key)
val = info.get(subkey)
dispatch_llen_key(key, val, db, plugin_instance)


def log_verbose(msg):
if not VERBOSE_LOGGING:
Expand Down

0 comments on commit fec2aed

Please sign in to comment.