From 7877a98bd9c00db5e81dd2f8c734cba2bab20be7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 12 Aug 2022 09:26:17 +0200 Subject: Merging upstream version 1.36.0. Signed-off-by: Daniel Baumann --- exporting/graphite/graphite.c | 34 ++++++++++++---------------------- exporting/graphite/graphite.h | 2 +- 2 files changed, 13 insertions(+), 23 deletions(-) (limited to 'exporting/graphite') diff --git a/exporting/graphite/graphite.c b/exporting/graphite/graphite.c index 84d4febf1..8ca094b3b 100644 --- a/exporting/graphite/graphite.c +++ b/exporting/graphite/graphite.c @@ -37,6 +37,7 @@ int init_graphite_instance(struct instance *instance) instance->metric_formatting = format_dimension_stored_graphite_plaintext; instance->end_chart_formatting = NULL; + instance->variables_formatting = NULL; instance->end_host_formatting = flush_host_labels; instance->end_batch_formatting = simple_connector_end_batch; @@ -71,7 +72,7 @@ int init_graphite_instance(struct instance *instance) * @param len the maximum number of characters copied. */ -void sanitize_graphite_label_value(char *dst, char *src, size_t len) +void sanitize_graphite_label_value(char *dst, const char *src, size_t len) { while (*src != '\0' && len) { if (isspace(*src) || *src == ';' || *src == '~') @@ -91,29 +92,18 @@ void sanitize_graphite_label_value(char *dst, char *src, size_t len) * @param host a data collecting host. * @return Always returns 0. */ + int format_host_labels_graphite_plaintext(struct instance *instance, RRDHOST *host) { - if (!instance->labels) - instance->labels = buffer_create(1024); + 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_graphite_label_value(value, label->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); + rrdlabels_to_buffer(host->host_labels, instance->labels_buffer, ";", "=", "", "", + exporting_labels_filter_callback, instance, + NULL, sanitize_graphite_label_value); return 0; } @@ -151,7 +141,7 @@ int format_dimension_collected_graphite_plaintext(struct instance *instance, RRD dimension_name, (host->tags) ? ";" : "", (host->tags) ? host->tags : "", - (instance->labels) ? buffer_tostring(instance->labels) : "", + (instance->labels_buffer) ? buffer_tostring(instance->labels_buffer) : "", rd->last_collected_value, (unsigned long long)rd->last_collected_time.tv_sec); @@ -183,21 +173,21 @@ int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM RRD_ID_LENGTH_MAX); time_t last_t; - calculated_number value = exporting_calculate_value_from_stored_data(instance, rd, &last_t); + NETDATA_DOUBLE value = exporting_calculate_value_from_stored_data(instance, rd, &last_t); if(isnan(value)) return 0; buffer_sprintf( instance->buffer, - "%s.%s.%s.%s%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n", + "%s.%s.%s.%s%s%s%s " NETDATA_DOUBLE_FORMAT " %llu\n", instance->config.prefix, (host == localhost) ? instance->config.hostname : host->hostname, chart_name, dimension_name, (host->tags) ? ";" : "", (host->tags) ? host->tags : "", - (instance->labels) ? buffer_tostring(instance->labels) : "", + (instance->labels_buffer) ? buffer_tostring(instance->labels_buffer) : "", value, (unsigned long long)last_t); diff --git a/exporting/graphite/graphite.h b/exporting/graphite/graphite.h index 993c12e57..79f87e46e 100644 --- a/exporting/graphite/graphite.h +++ b/exporting/graphite/graphite.h @@ -7,7 +7,7 @@ int init_graphite_instance(struct instance *instance); -void sanitize_graphite_label_value(char *dst, char *src, size_t len); +void sanitize_graphite_label_value(char *dst, const char *src, size_t len); int format_host_labels_graphite_plaintext(struct instance *instance, RRDHOST *host); int format_dimension_collected_graphite_plaintext(struct instance *instance, RRDDIM *rd); -- cgit v1.2.3