From 3c315f0fff93aa072472abc10815963ac0035268 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 12 Aug 2022 09:26:11 +0200 Subject: Adding upstream version 1.36.0. Signed-off-by: Daniel Baumann --- exporting/json/json.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'exporting/json') diff --git a/exporting/json/json.c b/exporting/json/json.c index 50278c5b8..45a8c9d9f 100644 --- a/exporting/json/json.c +++ b/exporting/json/json.c @@ -29,6 +29,7 @@ int init_json_instance(struct instance *instance) instance->metric_formatting = format_dimension_stored_json_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; @@ -87,6 +88,7 @@ int init_json_http_instance(struct instance *instance) instance->metric_formatting = format_dimension_stored_json_plaintext; instance->end_chart_formatting = NULL; + instance->variables_formatting = NULL; instance->end_host_formatting = flush_host_labels; instance->end_batch_formatting = close_batch_json_http; @@ -113,34 +115,20 @@ int init_json_http_instance(struct instance *instance) * @param host a data collecting host. * @return Always returns 0. */ + int format_host_labels_json_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; - buffer_strcat(instance->labels, "\"labels\":{"); - - int count = 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 * 2 + 1]; - sanitize_json_string(value, label->value, CONFIG_MAX_VALUE); - if (count > 0) - buffer_strcat(instance->labels, ","); - buffer_sprintf(instance->labels, "\"%s\":\"%s\"", label->key, value); - - count++; - } - netdata_rwlock_unlock(&host->labels.labels_rwlock); - - buffer_strcat(instance->labels, "},"); + buffer_strcat(instance->labels_buffer, "\"labels\":{"); + rrdlabels_to_buffer(host->host_labels, instance->labels_buffer, "", ":", "\"", ",", + exporting_labels_filter_callback, instance, + NULL, sanitize_json_string); + buffer_strcat(instance->labels_buffer, "},"); return 0; } @@ -203,7 +191,7 @@ int format_dimension_collected_json_plaintext(struct instance *instance, RRDDIM tags_pre, tags, tags_post, - instance->labels ? buffer_tostring(instance->labels) : "", + instance->labels_buffer ? buffer_tostring(instance->labels_buffer) : "", st->id, st->name, @@ -238,7 +226,7 @@ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd RRDHOST *host = st->rrdhost; 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; @@ -279,7 +267,7 @@ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd "\"id\":\"%s\"," "\"name\":\"%s\"," - "\"value\":" CALCULATED_NUMBER_FORMAT "," + "\"value\":" NETDATA_DOUBLE_FORMAT "," "\"timestamp\": %llu}", @@ -288,7 +276,7 @@ int format_dimension_stored_json_plaintext(struct instance *instance, RRDDIM *rd tags_pre, tags, tags_post, - instance->labels ? buffer_tostring(instance->labels) : "", + instance->labels_buffer ? buffer_tostring(instance->labels_buffer) : "", st->id, st->name, -- cgit v1.2.3