X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fwrite_redis.c;h=4bfcc73d2b5b92fa61bd37e8855a6b2d2657aad9;hb=b76f88c5bafa82e3c939eb65c13acd431e07cc01;hp=eb4e2c5915aa35c3059301f481c820fdfbb0af09;hpb=860bf13b5fb56582e8764e22cbb6837092cc2281;p=collectd.git diff --git a/src/write_redis.c b/src/write_redis.c index eb4e2c59..4bfcc73d 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -47,6 +47,7 @@ struct wr_node_s char *prefix; int database; int max_set_size; + _Bool store_rates; redisContext *conn; pthread_mutex_t lock; @@ -81,11 +82,12 @@ static int wr_write (const data_set_t *ds, /* {{{ */ memset (value, 0, sizeof (value)); value_size = sizeof (value); value_ptr = &value[0]; - status = format_values (value_ptr, value_size, ds, vl, /* store rates = */ 0); - pthread_mutex_lock (&node->lock); + status = format_values (value_ptr, value_size, ds, vl, node->store_rates); if (status != 0) return (status); + pthread_mutex_lock (&node->lock); + if (node->conn == NULL) { node->conn = redisConnectWithTimeout ((char *)node->host, node->port, node->timeout); @@ -124,7 +126,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ { rr = redisCommand (node->conn, "ZREMRANGEBYRANK %s %d %d", key, 0, (-1 * node->max_set_size) - 1); if (rr == NULL) - WARNING("ZREMRANGEBYRANK command error. database:%d message:%s", node->database, node->conn->errstr); + WARNING("ZREMRANGEBYRANK command error. key:%s message:%s", key, node->conn->errstr); else freeReplyObject (rr); } @@ -181,6 +183,7 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ node->prefix = NULL; node->database = 0; node->max_set_size = -1; + node->store_rates = 1; pthread_mutex_init (&node->lock, /* attr = */ NULL); status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name)); @@ -218,6 +221,9 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ else if (strcasecmp ("MaxSetSize", child->key) == 0) { status = cf_util_get_int (child, &node->max_set_size); } + else if (strcasecmp ("StoreRates", child->key) == 0) { + status = cf_util_get_boolean (child, &node->store_rates); + } else WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".", child->key);