diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-05-21 18:55:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-05-21 18:55:22 +0000 |
commit | 61d0027904ee9c040985b1642ca228737d616d03 (patch) | |
tree | c90838c137b4dc4a2de1cff9f2d7be5552d605e7 /web/api/formatters/charts2json.c | |
parent | Adding upstream version 1.14.0. (diff) | |
download | netdata-61d0027904ee9c040985b1642ca228737d616d03.tar.xz netdata-61d0027904ee9c040985b1642ca228737d616d03.zip |
Adding upstream version 1.15.0.upstream/1.15.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | web/api/formatters/charts2json.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/web/api/formatters/charts2json.c b/web/api/formatters/charts2json.c index 413f1a6d1..e4e2f4dfa 100644 --- a/web/api/formatters/charts2json.c +++ b/web/api/formatters/charts2json.c @@ -135,3 +135,56 @@ void charts2json(RRDHOST *host, BUFFER *wb) { buffer_sprintf(wb, "\n\t]\n}\n"); } + +// generate collectors list for the api/v1/info call + +struct collector { + char *plugin; + char *module; +}; + +struct array_printer { + int c; + BUFFER *wb; +}; + +int print_collector(void *entry, void *data) { + struct array_printer *ap = (struct array_printer *)data; + BUFFER *wb = ap->wb; + struct collector *col=(struct collector *) entry; + if(ap->c) buffer_strcat(wb, ","); + buffer_strcat(wb, "\n\t\t{\n\t\t\t\"plugin\": \""); + buffer_strcat(wb, col->plugin); + buffer_strcat(wb, "\",\n\t\t\t\"module\": \""); + buffer_strcat(wb, col->module); + buffer_strcat(wb, "\"\n\t\t}"); + (ap->c)++; + return 0; +} + +void chartcollectors2json(RRDHOST *host, BUFFER *wb) { + DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED); + RRDSET *st; + char name[500]; + + time_t now = now_realtime_sec(); + rrdhost_rdlock(host); + rrdset_foreach_read(st, host) { + if (rrdset_is_available_for_viewers(st)) { + struct collector col = { + .plugin = st->plugin_name ? st->plugin_name : "", + .module = st->module_name ? st->module_name : "" + }; + sprintf(name, "%s:%s", col.plugin, col.module); + dictionary_set(dict, name, &col, sizeof(struct collector)); + st->last_accessed_time = now; + } + } + rrdhost_unlock(host); + struct array_printer ap = { + .c = 0, + .wb = wb + }; + dictionary_get_all(dict, print_collector, &ap); + dictionary_destroy(dict); +} |