From: Gergely Nagy Date: Thu, 7 Apr 2016 06:59:08 +0000 (+0200) Subject: write_riemann: Add support for timeouts X-Git-Tag: collectd-5.6.0~339^2~7 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=113cbf06e13f7ea70e08651ab71ffcf916ccb02f;p=collectd.git write_riemann: Add support for timeouts Bump the riemann-c-client requirement to 1.8.0, which introduces riemann_client_set_timeout(). With this in place, the plugin can now accept the "Timeout" option, which specifies a timeout in seconds, for all blocking operations (except TLS handshake). Signed-off-by: Gergely Nagy --- diff --git a/configure.ac b/configure.ac index 09afe112..9cc9b552 100644 --- a/configure.ac +++ b/configure.ac @@ -5231,7 +5231,7 @@ PKG_CHECK_MODULES([LIBNOTIFY], [libnotify], [with_libnotify="no (pkg-config doesn't know libnotify)"] ) -PKG_CHECK_MODULES([RIEMANN_C], [riemann-client >= 1.6.0], +PKG_CHECK_MODULES([RIEMANN_C], [riemann-client >= 1.8.0], [with_riemann_c="yes"], [with_riemann_c="no (pbg-config doesn't know riemann-c-client)"]) diff --git a/src/write_riemann.c b/src/write_riemann.c index 3429976f..2b68e883 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -65,6 +65,7 @@ struct riemann_host { char *tls_ca_file; char *tls_cert_file; char *tls_key_file; + struct timeval timeout; }; static char **riemann_tags; @@ -96,6 +97,15 @@ static int wrr_connect(struct riemann_host *host) /* {{{ */ node, port); return -1; } + if (host->timeout.tv_sec != 0) { + if (riemann_client_set_timeout(host->client, &host->timeout) != 0) { + riemann_client_free(host->client); + host->client = NULL; + WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%d", + node, port); + return -1; + } + } DEBUG("write_riemann plugin: got a successful connection for: %s:%d", node, port); @@ -639,6 +649,8 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ host->ttl_factor = RIEMANN_TTL_FACTOR; host->client = NULL; host->client_type = RIEMANN_CLIENT_TCP; + host->timeout.tv_sec = 0; + host->timeout.tv_usec = 0; status = cf_util_get_string(ci, &host->name); if (status != 0) { @@ -679,6 +691,10 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_int(child, &host->batch_max); if (status != 0) break; + } else if (strcasecmp("Timeout", child->key) == 0) { + status = cf_util_get_int(child, (int *)&host->timeout.tv_sec); + if (status != 0) + break; } else if (strcasecmp("Port", child->key) == 0) { host->port = cf_util_get_port_number(child); if (host->port == -1) {