summaryrefslogtreecommitdiffstats
path: root/web/api/formatters/rrdset2json.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/api/formatters/rrdset2json.c')
-rw-r--r--web/api/formatters/rrdset2json.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/web/api/formatters/rrdset2json.c b/web/api/formatters/rrdset2json.c
index c83b22e639..26b9c1d481 100644
--- a/web/api/formatters/rrdset2json.c
+++ b/web/api/formatters/rrdset2json.c
@@ -4,8 +4,10 @@
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;
@@ -16,20 +18,8 @@ void chart_labels2json(RRDSET *st, BUFFER *wb, size_t indentation)
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