summaryrefslogtreecommitdiffstats
path: root/exporting/opentsdb/opentsdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'exporting/opentsdb/opentsdb.c')
-rw-r--r--exporting/opentsdb/opentsdb.c70
1 files changed, 23 insertions, 47 deletions
diff --git a/exporting/opentsdb/opentsdb.c b/exporting/opentsdb/opentsdb.c
index 7ed88fd6d8..d6ce98ce45 100644
--- a/exporting/opentsdb/opentsdb.c
+++ b/exporting/opentsdb/opentsdb.c
@@ -124,13 +124,14 @@ int init_opentsdb_http_instance(struct instance *instance)
* @param len the maximum number of characters copied.
*/
-void sanitize_opentsdb_label_value(char *dst, char *src, size_t len)
+void sanitize_opentsdb_label_value(char *dst, const char *src, size_t len)
{
while (*src != '\0' && len) {
- if (isalpha(*src) || isdigit(*src) || *src == '-' || *src == '_' || *src == '.' || *src == '/' || IS_UTF8_BYTE(*src))
+ if (isalpha(*src) || isdigit(*src) || *src == '-' || *src == '.' || *src == '/' || IS_UTF8_BYTE(*src))
*dst++ = *src;
else
*dst++ = '_';
+
src++;
len--;
}
@@ -144,28 +145,18 @@ void sanitize_opentsdb_label_value(char *dst, char *src, size_t len)
* @param host a data collecting host.
* @return Always returns 0.
*/
-int format_host_labels_opentsdb_telnet(struct instance *instance, RRDHOST *host)
-{
- if (!instance->labels)
- instance->labels = buffer_create(1024);
+
+int format_host_labels_opentsdb_telnet(struct instance *instance, RRDHOST *host) {
+ if(!instance->labels_buffer)
+ instance->labels_buffer = buffer_create(1024);
if (unlikely(!sending_labels_configured(instance)))
return 0;
- rrdhost_check_rdlock(host);
- netdata_rwlock_rdlock(&host->labels.labels_rwlock);
- for (struct label *label = host->labels.head; label; label = label->next) {
- if (!should_send_label(instance, label))
- continue;
-
- char value[CONFIG_MAX_VALUE + 1];
- sanitize_opentsdb_label_value(value, label->value, CONFIG_MAX_VALUE);
-
- if (*value)
- buffer_sprintf(instance->labels, " %s=%s", label->key, value);
- }
- netdata_rwlock_unlock(&host->labels.labels_rwlock);
-
+ buffer_strcat(instance->labels_buffer, " ");
+ rrdlabels_to_buffer(host->host_labels, instance->labels_buffer, "", "=", "", " ",
+ exporting_labels_filter_callback, instance,
+ NULL, sanitize_opentsdb_label_value);
return 0;
}
@@ -204,7 +195,7 @@ int format_dimension_collected_opentsdb_telnet(struct instance *instance, RRDDIM
(host == localhost) ? instance->config.hostname : host->hostname,
(host->tags) ? " " : "",
(host->tags) ? host->tags : "",
- (instance->labels) ? buffer_tostring(instance->labels) : "");
+ (instance->labels_buffer) ? buffer_tostring(instance->labels_buffer) : "");
return 0;
}
@@ -250,7 +241,7 @@ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *r
(host == localhost) ? instance->config.hostname : host->hostname,
(host->tags) ? " " : "",
(host->tags) ? host->tags : "",
- (instance->labels) ? buffer_tostring(instance->labels) : "");
+ (instance->labels_buffer) ? buffer_tostring(instance->labels_buffer) : "");
return 0;
}
@@ -287,33 +278,18 @@ void opentsdb_http_prepare_header(struct instance *instance)
* @param host a data collecting host.
* @return Always returns 0.
*/
-int format_host_labels_opentsdb_http(struct instance *instance, RRDHOST *host)
-{
- if (!instance->labels)
- instance->labels = buffer_create(1024);
+
+int format_host_labels_opentsdb_http(struct instance *instance, RRDHOST *host) {
+ if (!instance->labels_buffer)
+ instance->labels_buffer = buffer_create(1024);
if (unlikely(!sending_labels_configured(instance)))
return 0;
- rrdhost_check_rdlock(host);
- netdata_rwlock_rdlock(&host->labels.labels_rwlock);
- for (struct label *label = host->labels.head; label; label = label->next) {
- if (!should_send_label(instance, label))
- continue;
-
- char escaped_value[CONFIG_MAX_VALUE * 2 + 1];
- sanitize_json_string(escaped_value, label->value, CONFIG_MAX_VALUE);
-
- char value[CONFIG_MAX_VALUE + 1];
- sanitize_opentsdb_label_value(value, escaped_value, CONFIG_MAX_VALUE);
-
- if (*value) {
- buffer_strcat(instance->labels, ",");
- buffer_sprintf(instance->labels, "\"%s\":\"%s\"", label->key, value);
- }
- }
- netdata_rwlock_unlock(&host->labels.labels_rwlock);
-
+ buffer_strcat(instance->labels_buffer, ",");
+ rrdlabels_to_buffer(host->host_labels, instance->labels_buffer, "", ":", "\"", ",",
+ exporting_labels_filter_callback, instance,
+ NULL, sanitize_opentsdb_label_value);
return 0;
}
@@ -362,7 +338,7 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *
(host == localhost) ? instance->config.hostname : host->hostname,
(host->tags) ? " " : "",
(host->tags) ? host->tags : "",
- instance->labels ? buffer_tostring(instance->labels) : "");
+ instance->labels_buffer ? buffer_tostring(instance->labels_buffer) : "");
return 0;
}
@@ -418,7 +394,7 @@ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd)
(host == localhost) ? instance->config.hostname : host->hostname,
(host->tags) ? " " : "",
(host->tags) ? host->tags : "",
- instance->labels ? buffer_tostring(instance->labels) : "");
+ instance->labels_buffer ? buffer_tostring(instance->labels_buffer) : "");
return 0;
}