summaryrefslogtreecommitdiffstats
path: root/exporting/json
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-08-12 07:26:17 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-08-12 07:26:17 +0000
commit7877a98bd9c00db5e81dd2f8c734cba2bab20be7 (patch)
treed18b767250f7c7ced9b8abe2ece784ac1fe24d3e /exporting/json
parentReleasing debian version 1.35.1-2. (diff)
downloadnetdata-7877a98bd9c00db5e81dd2f8c734cba2bab20be7.tar.xz
netdata-7877a98bd9c00db5e81dd2f8c734cba2bab20be7.zip
Merging upstream version 1.36.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'exporting/json')
-rw-r--r--exporting/json/json.c40
1 files changed, 14 insertions, 26 deletions
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,