diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-08-12 07:26:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-08-12 07:26:11 +0000 |
commit | 3c315f0fff93aa072472abc10815963ac0035268 (patch) | |
tree | a95f6a96e0e7bd139c010f8dc60b40e5b3062a99 /web/api/formatters/rrdset2json.c | |
parent | Adding upstream version 1.35.1. (diff) | |
download | netdata-upstream/1.36.0.tar.xz netdata-upstream/1.36.0.zip |
Adding upstream version 1.36.0.upstream/1.36.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/api/formatters/rrdset2json.c')
-rw-r--r-- | web/api/formatters/rrdset2json.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/web/api/formatters/rrdset2json.c b/web/api/formatters/rrdset2json.c index c83b22e63..de8d87bae 100644 --- a/web/api/formatters/rrdset2json.c +++ b/web/api/formatters/rrdset2json.c @@ -4,32 +4,22 @@ void chart_labels2json(RRDSET *st, BUFFER *wb, size_t indentation) { + if(unlikely(!st->state || !st->state->chart_labels)) + return; + char tabs[11]; - struct label_index *labels = &st->state->labels; if (indentation > 10) indentation = 10; tabs[0] = '\0'; while (indentation) { - strcat(tabs, "\t"); + strcat(tabs, "\t\t"); indentation--; } - int count = 0; - netdata_rwlock_rdlock(&labels->labels_rwlock); - for (struct label *label = labels->head; label; label = label->next) { - if(count > 0) buffer_strcat(wb, ",\n"); - buffer_strcat(wb, tabs); - - char value[CONFIG_MAX_VALUE * 2 + 1]; - sanitize_json_string(value, label->value, CONFIG_MAX_VALUE * 2); - buffer_sprintf(wb, "\"%s\": \"%s\"", label->key, value); - - count++; - } + rrdlabels_to_buffer(st->state->chart_labels, wb, tabs, ":", "\"", ",\n", NULL, NULL, NULL, NULL); buffer_strcat(wb, "\n"); - netdata_rwlock_unlock(&labels->labels_rwlock); } // generate JSON for the /api/v1/chart API call @@ -95,14 +85,14 @@ void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memor "\t\t\t\"dimensions\": {\n", st->update_every); - unsigned long memory = st->memsize; + unsigned long memory = sizeof(RRDSET) + st->memsize; size_t dimensions = 0; RRDDIM *rd; rrddim_foreach_read(rd, st) { if(rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN) || rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) continue; - memory += rd->memsize; + memory += sizeof(RRDDIM) + rd->memsize; if (dimensions) buffer_strcat(wb, ",\n\t\t\t\t\""); |