From: Florian Forster Date: Thu, 25 Jun 2015 20:11:17 +0000 (+0200) Subject: write_redis plugin: Use the prefix for the "values" set, too. X-Git-Tag: collectd-5.6.0~671 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d561993fd1bfb93df203484c4c225aca8b45f041;p=collectd.git write_redis plugin: Use the prefix for the "values" set, too. Make the code match the documentation and use the prefix for the set of all metrics, too. Also add documentation for the "Prefix" option and let the default prefix be set at compile time. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 5a4c4674..bafdddb4 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1366,6 +1366,7 @@ # Host "localhost" # Port "6379" # Timeout 1000 +# Prefix "collectd/" # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 9412ed37..b2aab213 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7494,15 +7494,16 @@ Synopsis: Host "localhost" Port "6379" Timeout 1000 - Prefix "examplePrefix" + Prefix "collectd/" Values are submitted to I, using the metric name as the key, and 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 if a Prefix was specified and can be -retrieved using the C I command. See +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 L and L for details. @@ -7537,6 +7538,13 @@ that numerical port numbers must be given as a string, too. The B option sets the socket connection timeout, in milliseconds. +=item B I + +Prefix used when constructing the name of the I and the I +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. + =back =head2 Plugin C diff --git a/src/write_redis.c b/src/write_redis.c index 24bcfc8c..909f51d5 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -1,6 +1,6 @@ /** * collectd - src/write_redis.c - * Copyright (C) 2010 Florian Forster + * Copyright (C) 2010-2015 Florian Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -33,6 +33,10 @@ #include #include +#ifndef REDIS_DEFAULT_PREFIX +# define REDIS_DEFAULT_PREFIX "collectd/" +#endif + struct wr_node_s { char name[DATA_MAX_NAME_LEN]; @@ -68,12 +72,9 @@ static int wr_write (const data_set_t *ds, /* {{{ */ status = FORMAT_VL (ident, sizeof (ident), vl); if (status != 0) return (status); - if (node->prefix == NULL) { - ssnprintf (key, sizeof (key), "collectd/%s", ident); - } - else { - ssnprintf (key, sizeof (key), "%s/%s", node->prefix, ident); - } + ssnprintf (key, sizeof (key), "%s%s", + (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX, + ident); ssnprintf (time, sizeof (time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time)); memset (value, 0, sizeof (value)); @@ -143,7 +144,9 @@ static int wr_write (const data_set_t *ds, /* {{{ */ if (rr==NULL) WARNING("ZADD command error. key:%s message:%s", key, node->conn->errstr); - rr = redisCommand (node->conn, "SADD collectd/values %s", ident); + rr = redisCommand (node->conn, "SADD %svalues %s", + (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX, + ident); if (rr==NULL) WARNING("SADD command error. ident:%s message:%s", ident, node->conn->errstr);