X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fwrite_riemann.c;h=ac6b8fbf7b2b7a42afe1eecd07895ef1f2d82cef;hb=81e573dbdd703fa5196a1531aba92630c6ceb7d3;hp=1836b6b1d67cbace9f043cbbe47776eee924c989;hpb=548543e17ac17a2855959cd73d13771c7e6780d3;p=collectd.git diff --git a/src/write_riemann.c b/src/write_riemann.c index 1836b6b1..ac6b8fbf 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -28,11 +28,9 @@ * Gergely Nagy */ -#include -#include -#include - #include "collectd.h" + + #include "plugin.h" #include "common.h" #include "configfile.h" @@ -40,6 +38,9 @@ #include "utils_complain.h" #include "write_riemann_threshold.h" +#include +#include + #define RIEMANN_HOST "localhost" #define RIEMANN_PORT 5555 #define RIEMANN_TTL_FACTOR 2.0 @@ -136,21 +137,18 @@ static int wrr_disconnect(struct riemann_host *host) /* {{{ */ * * Acquires the host lock, disconnects on errors. */ -static int wrr_send(struct riemann_host *host, riemann_message_t *msg) /* {{{ */ +static int wrr_send_nolock(struct riemann_host *host, riemann_message_t *msg) /* {{{ */ { int status = 0; - pthread_mutex_lock (&host->lock); status = wrr_connect(host); if (status != 0) { - pthread_mutex_unlock(&host->lock); return status; } status = riemann_client_send_message(host->client, msg); if (status != 0) { wrr_disconnect(host); - pthread_mutex_unlock(&host->lock); return status; } @@ -166,16 +164,24 @@ static int wrr_send(struct riemann_host *host, riemann_message_t *msg) /* {{{ */ if (response == NULL) { wrr_disconnect(host); - pthread_mutex_unlock(&host->lock); return errno; } riemann_message_free(response); } - pthread_mutex_unlock (&host->lock); return 0; } /* }}} int wrr_send */ +static int wrr_send(struct riemann_host *host, riemann_message_t *msg) +{ + int status = 0; + + pthread_mutex_lock (&host->lock); + status = wrr_send_nolock(host, msg); + pthread_mutex_unlock (&host->lock); + return status; +} + static riemann_message_t *wrr_notification_to_message(struct riemann_host *host, /* {{{ */ notification_t const *n) { @@ -456,30 +462,16 @@ static int wrr_batch_flush_nolock(cdtime_t timeout, cdtime_t now; int status = 0; + now = cdtime(); if (timeout > 0) { - now = cdtime(); - if ((host->batch_init + timeout) > now) + if ((host->batch_init + timeout) > now) { return status; + } } - wrr_send(host, host->batch_msg); + wrr_send_nolock(host, host->batch_msg); riemann_message_free(host->batch_msg); - if (host->client_type != RIEMANN_CLIENT_UDP) - { - riemann_message_t *response; - - response = riemann_client_recv_message(host->client); - - if (!response) - { - wrr_disconnect(host); - return errno; - } - - riemann_message_free(response); - } - - host->batch_init = cdtime(); + host->batch_init = now; host->batch_msg = NULL; return status; } @@ -606,7 +598,7 @@ static int wrr_write(const data_set_t *ds, /* {{{ */ } if (host->client_type != RIEMANN_CLIENT_UDP && host->batch_mode) { - wrr_batch_add_value_list(host, ds, vl, statuses); + wrr_batch_add_value_list(host, ds, vl, statuses); } else { msg = wrr_value_list_to_message(host, ds, vl, statuses); if (msg == NULL)