From: Sebastian Pfahl Date: Fri, 10 Jul 2015 11:33:11 +0000 (+0000) Subject: Added option to choose redis database to use X-Git-Tag: collectd-5.6.0~638^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b267792073e9a88cece5574782760d17db12a15d;p=collectd.git Added option to choose redis database to use --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index b2aab213..87844e13 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7495,6 +7495,7 @@ Synopsis: Port "6379" Timeout 1000 Prefix "collectd/" + Database 1 @@ -7503,7 +7504,8 @@ the timestamp as the score. Retrieving a date range can then be done using the C I command. Additionnally, all the identifiers of these I are kept in a I called C (or C<${prefix}/values> if the B option was specified) and can be retrieved -using the C I command. See +using the C I command. You can specify the database to use +with the B parameter (default is C<0>). See L and L for details. @@ -7545,6 +7547,10 @@ containing all metrics. Defaults to C, so metrics will have names like C. When setting this to something different, it is recommended but not required to include a trailing slash in I. +=item B I + +This index selects the redis database to use for writing operations. Defaults to C<0>. + =back =head2 Plugin C diff --git a/src/write_redis.c b/src/write_redis.c index fa58ad2a..7ba476c9 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -45,6 +45,7 @@ struct wr_node_s int port; struct timeval timeout; char *prefix; + int database; redisContext *conn; pthread_mutex_t lock; @@ -138,6 +139,12 @@ static int wr_write (const data_set_t *ds, /* {{{ */ pthread_mutex_unlock (&node->lock); return (-1); } + + rr = redisCommand(node->conn, "SELECT %d", node->database); + if (rr == NULL) + WARNING("SELECT command error. database:%d message:%s", node->database, node->conn->errstr); + else + freeReplyObject (rr); } rr = redisCommand (node->conn, "ZADD %s %s %s", key, time, value); @@ -196,6 +203,7 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ node->timeout.tv_usec = 1000; node->conn = NULL; node->prefix = NULL; + node->database = 0; pthread_mutex_init (&node->lock, /* attr = */ NULL); status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name)); @@ -227,6 +235,9 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ else if (strcasecmp ("Prefix", child->key) == 0) { status = cf_util_get_string (child, &node->prefix); } + else if (strcasecmp ("Database", child->key) == 0) { + status = cf_util_get_int (child, &node->database); + } else WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".", child->key);