diff --git a/redis_info.py b/redis_info.py index 9db3a75..e3adf74 100644 --- a/redis_info.py +++ b/redis_info.py @@ -39,6 +39,7 @@ CONFIGS = [] REDIS_INFO = {} + def fetch_info(conf): """Connect to Redis server and request info""" try: @@ -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, @@ -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: @@ -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 = {} @@ -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 @@ -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): """ @@ -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) @@ -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: