From: Victor Seva Date: Thu, 14 Nov 2013 10:59:32 +0000 (+0100) Subject: remove all credis left. Migrate write_redis too. X-Git-Tag: collectd-5.5.0~139^2~7 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=afebdd7c638962fec65e8188e3dd77f6bf85554f;p=collectd.git remove all credis left. Migrate write_redis too. Conflicts: README --- diff --git a/README b/README index 3e3a030b..e749a5f3 100644 --- a/README +++ b/README @@ -607,9 +607,9 @@ Prerequisites * libclntsh (optional) Used by the `oracle' plugin. - * libcredis (optional) - Used by the `redis' plugin. Please note that you require a 0.2.2 version - or higher. + * libhiredis (optional) + Used by the redis plugin. Please note that you require a 0.10.0 version + or higher. * libcurl (optional) If you want to use the `apache', `ascent', `bind', `curl', `curl_json', diff --git a/configure.ac b/configure.ac index 15fdd17c..9c3dfed3 100644 --- a/configure.ac +++ b/configure.ac @@ -1579,64 +1579,6 @@ fi AM_CONDITIONAL(BUILD_WITH_LIBAQUAERO5, test "x$with_libaquaero5" = "xyes") # }}} -# --with-libcredis {{{ -AC_ARG_WITH(libcredis, [AS_HELP_STRING([--with-libcredis@<:@=PREFIX@:>@], [Path to libcredis.])], -[ - if test "x$withval" = "xyes" - then - with_libcredis="yes" - else if test "x$withval" = "xno" - then - with_libcredis="no" - else - with_libcredis="yes" - LIBCREDIS_CPPFLAGS="$LIBCREDIS_CPPFLAGS -I$withval/include" - LIBCREDIS_LDFLAGS="$LIBCREDIS_LDFLAGS -L$withval/lib" - fi; fi -], -[with_libcredis="yes"]) - -SAVE_CPPFLAGS="$CPPFLAGS" -SAVE_LDFLAGS="$LDFLAGS" - -CPPFLAGS="$CPPFLAGS $LIBCREDIS_CPPFLAGS" -LDFLAGS="$LDFLAGS $LIBCREDIS_LDFLAGS" - -if test "x$with_libcredis" = "xyes" -then - if test "x$LIBCREDIS_CPPFLAGS" != "x" - then - AC_MSG_NOTICE([libcredis CPPFLAGS: $LIBCREDIS_CPPFLAGS]) - fi - AC_CHECK_HEADERS(credis.h, - [with_libcredis="yes"], - [with_libcredis="no (credis.h not found)"]) -fi -if test "x$with_libcredis" = "xyes" -then - if test "x$LIBCREDIS_LDFLAGS" != "x" - then - AC_MSG_NOTICE([libcredis LDFLAGS: $LIBCREDIS_LDFLAGS]) - fi - AC_CHECK_LIB(credis, credis_info, - [with_libcredis="yes"], - [with_libcredis="no (symbol 'credis_info' not found)"]) - -fi - -CPPFLAGS="$SAVE_CPPFLAGS" -LDFLAGS="$SAVE_LDFLAGS" - -if test "x$with_libcredis" = "xyes" -then - BUILD_WITH_LIBCREDIS_CPPFLAGS="$LIBCREDIS_CPPFLAGS" - BUILD_WITH_LIBCREDIS_LDFLAGS="$LIBCREDIS_LDFLAGS" - AC_SUBST(BUILD_WITH_LIBCREDIS_CPPFLAGS) - AC_SUBST(BUILD_WITH_LIBCREDIS_LDFLAGS) -fi -AM_CONDITIONAL(BUILD_WITH_LIBCREDIS, test "x$with_libcredis" = "xyes") -# }}} - # --with-libhiredis {{{ AC_ARG_WITH(libhiredis, [AS_HELP_STRING([--with-libhiredis@<:@=PREFIX@:>@], [Path to libhiredis.])], @@ -5495,7 +5437,7 @@ AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin] AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin]) AC_PLUGIN([write_kafka], [$with_librdkafka], [Kafka output plugin]) AC_PLUGIN([write_mongodb], [$with_libmongoc], [MongoDB output plugin]) -AC_PLUGIN([write_redis], [$with_libcredis], [Redis output plugin]) +AC_PLUGIN([write_redis], [$with_libhiredis], [Redis output plugin]) AC_PLUGIN([write_riemann], [$have_protoc_c], [Riemann output plugin]) AC_PLUGIN([write_tsdb], [yes], [TSDB output plugin]) AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics]) @@ -5685,7 +5627,6 @@ Configuration: libaquaero5 . . . . . $with_libaquaero5 libcurl . . . . . . . $with_libcurl libdbi . . . . . . . $with_libdbi - libcredis . . . . . . $with_libcredis libhiredis . . . . . $with_libhiredis libesmtp . . . . . . $with_libesmtp libganglia . . . . . $with_libganglia diff --git a/src/Makefile.am b/src/Makefile.am index ee7cf6ba..71d4c96a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1167,9 +1167,9 @@ endif if BUILD_PLUGIN_WRITE_REDIS pkglib_LTLIBRARIES += write_redis.la write_redis_la_SOURCES = write_redis.c -write_redis_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBCREDIS_LDFLAGS) -write_redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCREDIS_CPPFLAGS) -write_redis_la_LIBADD = -lcredis +write_redis_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBHIREDIS_LDFLAGS) +write_redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBHIREDIS_CPPFLAGS) +write_redis_la_LIBADD = -lhiredis endif if BUILD_PLUGIN_WRITE_RIEMANN diff --git a/src/write_redis.c b/src/write_redis.c index 3defacae..1b127451 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -30,7 +30,8 @@ #include "configfile.h" #include -#include +#include +#include struct wr_node_s { @@ -38,9 +39,9 @@ struct wr_node_s char *host; int port; - int timeout; + struct timeval timeout; - REDIS conn; + redisContext *conn; pthread_mutex_t lock; }; typedef struct wr_node_s wr_node_t; @@ -59,6 +60,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ size_t value_size; char *value_ptr; int status; + redisReply *rr; int i; status = FORMAT_VL (ident, sizeof (ident), vl); @@ -105,7 +107,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ if (node->conn == NULL) { - node->conn = credis_connect (node->host, node->port, node->timeout); + node->conn = redisConnectWithTimeout ((char *)node->host, node->port, node->timeout); if (node->conn == NULL) { ERROR ("write_redis plugin: Connecting to host \"%s\" (port %i) failed.", @@ -116,12 +118,15 @@ static int wr_write (const data_set_t *ds, /* {{{ */ } } - /* "credis_zadd" doesn't handle a NULL pointer gracefully, so I'd rather - * have a meaningful assertion message than a normal segmentation fault. */ assert (node->conn != NULL); - status = credis_zadd (node->conn, key, (double) vl->time, value); + rr = redisCommand (node->conn, "ZADD %b %f %b", key, sizeof (key), + (double) vl->time, value, sizeof (value)); + if (rr==NULL) + WARNING("ZADD command error. key:%s", key); - credis_sadd (node->conn, "collectd/values", ident); + rr = redisCommand (node->conn, "SADD collectd/values %b", ident, sizeof(ident)); + if (rr==NULL) + WARNING("SADD command error. ident:%s", ident); pthread_mutex_unlock (&node->lock); @@ -137,7 +142,7 @@ static void wr_config_free (void *ptr) /* {{{ */ if (node->conn != NULL) { - credis_close (node->conn); + redisFree (node->conn); node->conn = NULL; } @@ -148,6 +153,7 @@ static void wr_config_free (void *ptr) /* {{{ */ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ { wr_node_t *node; + int timeout; int status; int i; @@ -157,7 +163,8 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ memset (node, 0, sizeof (*node)); node->host = NULL; node->port = 0; - node->timeout = 1000; + node->timeout.tv_sec = 0; + node->timeout.tv_usec = 1000; node->conn = NULL; pthread_mutex_init (&node->lock, /* attr = */ NULL); @@ -183,8 +190,10 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ status = 0; } } - else if (strcasecmp ("Timeout", child->key) == 0) - status = cf_util_get_int (child, &node->timeout); + else if (strcasecmp ("Timeout", child->key) == 0) { + status = cf_util_get_int (child, &timeout); + if (status == 0) node->timeout.tv_usec = timeout; + } else WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".", child->key);