From 2d5930f9711a6b1927f2d0c88cc276f2c0ff6ef7 Mon Sep 17 00:00:00 2001 From: bufadu Date: Wed, 3 May 2017 14:49:24 +0200 Subject: [PATCH] redis: adding support for key count per database --- src/redis.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/redis.c b/src/redis.c index ea888ca6..4e04230b 100644 --- a/src/redis.c +++ b/src/redis.c @@ -353,6 +353,41 @@ static int redis_handle_query(redisContext *rh, redis_node_t *rn, return 0; } /* }}} int redis_handle_query */ +static int redis_db_stats(char *node, char const *info_line) /* {{{ */ +{ + unsigned char db; + unsigned char max_db = 16; + static char field_name[10]; + static char db_id[3]; + char *str; + static char buf[MAX_REDIS_VAL_SIZE]; + value_t val; + int i; + + for (db = 0; db < max_db; db++) { + sprintf(field_name, "db%d:keys", db); + + str = strstr(info_line, field_name); + if (str) { + str += strlen(field_name) + 1; /* also skip the '=' */ + for (i = 0; (*str && (isdigit((unsigned char)*str) || *str == '.')); i++, str++) + buf[i] = *str; + buf[i] = '\0'; + + if (parse_value(buf, &val, DS_TYPE_GAUGE) == -1) { + WARNING("redis plugin: Unable to parse field `%s'.", field_name); + return (-1); + } + + sprintf(db_id, "%d", db); + redis_submit (node, "records", db_id, val); + } + } + return (0); + +} /* }}} int redis_db_stats */ + + static int redis_read(void) /* {{{ */ { for (redis_node_t *rn = nodes_head; rn != NULL; rn = rn->next) { @@ -429,6 +464,8 @@ static int redis_read(void) /* {{{ */ redis_handle_info(rn->name, rr->str, "total_bytes", "output", "total_net_output_bytes", DS_TYPE_DERIVE); + redis_db_stats (rn->name, rr->str); + for (redis_query_t *rq = rn->queries; rq != NULL; rq = rq->next) redis_handle_query(rh, rn, rq); -- 2.11.0