From: jaroug Date: Fri, 14 Apr 2017 15:01:57 +0000 (+0200) Subject: Add support for the new TTL parameter - kairosdb only X-Git-Tag: collectd-5.8.0~193^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d7b44c1b013725232b4a156af303ed2fce9a5902;p=collectd.git Add support for the new TTL parameter - kairosdb only --- diff --git a/src/utils_format_kairosdb.c b/src/utils_format_kairosdb.c index 2a14f0ed..224e8a52 100644 --- a/src/utils_format_kairosdb.c +++ b/src/utils_format_kairosdb.c @@ -183,7 +183,7 @@ static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */ const data_set_t *ds, const value_list_t *vl, int store_rates, char const *const *http_attrs, - size_t http_attrs_num) { + size_t http_attrs_num, int data_ttl) { char temp[512]; size_t offset = 0; int status; @@ -230,6 +230,9 @@ static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */ memset(temp, 0, sizeof(temp)); + if (data_ttl != 0) + BUFFER_ADD(", \"ttl\": %i", data_ttl); + BUFFER_ADD(", \"tags\":\{"); BUFFER_ADD("\"host\": \"%s\"", vl->host); @@ -260,12 +263,12 @@ static int format_kairosdb_value_list_nocheck( char *buffer, /* {{{ */ size_t *ret_buffer_fill, size_t *ret_buffer_free, const data_set_t *ds, const value_list_t *vl, int store_rates, size_t temp_size, - char const *const *http_attrs, size_t http_attrs_num) { + char const *const *http_attrs, size_t http_attrs_num, int data_ttl) { char temp[temp_size]; int status; status = value_list_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates, - http_attrs, http_attrs_num); + http_attrs, http_attrs_num, data_ttl); if (status != 0) return (status); temp_size = strlen(temp); @@ -334,7 +337,7 @@ int format_kairosdb_value_list(char *buffer, /* {{{ */ size_t *ret_buffer_fill, size_t *ret_buffer_free, const data_set_t *ds, const value_list_t *vl, int store_rates, char const *const *http_attrs, - size_t http_attrs_num) { + size_t http_attrs_num, int data_ttl) { if ((buffer == NULL) || (ret_buffer_fill == NULL) || (ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL)) return (-EINVAL); @@ -344,7 +347,7 @@ int format_kairosdb_value_list(char *buffer, /* {{{ */ return (format_kairosdb_value_list_nocheck( buffer, ret_buffer_fill, ret_buffer_free, ds, vl, store_rates, - (*ret_buffer_free) - 2, http_attrs, http_attrs_num)); + (*ret_buffer_free) - 2, http_attrs, http_attrs_num, data_ttl)); } /* }}} int format_kairosdb_value_list */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/utils_format_kairosdb.h b/src/utils_format_kairosdb.h index b6aa39d4..3a4c7c77 100644 --- a/src/utils_format_kairosdb.h +++ b/src/utils_format_kairosdb.h @@ -41,7 +41,7 @@ int format_kairosdb_value_list(char *buffer, size_t *ret_buffer_fill, size_t *ret_buffer_free, const data_set_t *ds, const value_list_t *vl, int store_rates, char const *const *http_attrs, - size_t http_attrs_num); + size_t http_attrs_num, int data_ttl); int format_kairosdb_finalize(char *buffer, size_t *ret_buffer_fill, size_t *ret_buffer_free); diff --git a/src/write_http.c b/src/write_http.c index c6efe079..097101f4 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -78,6 +78,8 @@ struct wh_callback_s { cdtime_t send_buffer_init_time; pthread_mutex_t send_lock; + + int data_ttl; }; typedef struct wh_callback_s wh_callback_t; @@ -473,7 +475,8 @@ static int wh_write_kairosdb(const data_set_t *ds, status = format_kairosdb_value_list( cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl, - cb->store_rates, (char const *const *)http_attrs, http_attrs_num); + cb->store_rates, (char const *const *)http_attrs, http_attrs_num, + cb->data_ttl); if (status == -ENOMEM) { status = wh_flush_nolock(/* timeout = */ 0, cb); if (status != 0) { @@ -484,7 +487,8 @@ static int wh_write_kairosdb(const data_set_t *ds, status = format_kairosdb_value_list( cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl, - cb->store_rates, (char const *const *)http_attrs, http_attrs_num); + cb->store_rates, (char const *const *)http_attrs, http_attrs_num, + cb->data_ttl); } if (status != 0) { pthread_mutex_unlock(&cb->send_lock); @@ -624,6 +628,7 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */ cb->headers = NULL; cb->send_metrics = 1; cb->send_notifications = 0; + cb->data_ttl = 0; pthread_mutex_init(&cb->send_lock, /* attr = */ NULL); @@ -733,6 +738,8 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */ DEBUG("write_http plugin: got attribute: %s => %s", key, val); sfree(key); sfree(val); + } else if (strcasecmp("TTL", child->key) == 0) { + status = cf_util_get_int(child, &cb->data_ttl); } else { ERROR("write_http plugin: Invalid configuration " "option: %s.",