diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2020-08-26 14:50:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 14:50:37 +0200 |
commit | ab7ff3131f3698710e0bd9fa3c66d31a3a194725 (patch) | |
tree | a78efc8cc829c2519b69e73e24d74e713c5105bb /web | |
parent | a11d33bba77043b28cf2b0dac4989cd189c635b2 (diff) |
Adds claimed_id streaming (#9804)
* streams claimed_id of child nodes to parents
* adds this information into /api/v1/info
Diffstat (limited to 'web')
-rw-r--r-- | web/api/web_api_v1.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index 09366de86a..b02814dc49 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -774,18 +774,48 @@ static inline void web_client_api_request_v1_info_summary_alarm_statuses(RRDHOST } static inline void web_client_api_request_v1_info_mirrored_hosts(BUFFER *wb) { - RRDHOST *rc; + RRDHOST *host; int count = 0; + + buffer_strcat(wb, "\t\"mirrored_hosts\": [\n"); rrd_rdlock(); - rrdhost_foreach_read(rc) { - if (rrdhost_flag_check(rc, RRDHOST_FLAG_ARCHIVED)) + rrdhost_foreach_read(host) { + if (rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)) continue; - if(count > 0) buffer_strcat(wb, ",\n"); - buffer_sprintf(wb, "\t\t\"%s\"", rc->hostname); + if (count > 0) + buffer_strcat(wb, ",\n"); + + buffer_sprintf(wb, "\t\t\"%s\"", host->hostname); + count++; + } + + buffer_strcat(wb, "\n\t],\n\t\"mirrored_hosts_status\": [\n"); + count = 0; + rrdhost_foreach_read(host) + { + if (rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)) + continue; + if (count > 0) + buffer_strcat(wb, ",\n"); + + netdata_mutex_lock(&host->receiver_lock); + buffer_sprintf( + wb, "\t\t{ \"guid\": \"%s\", \"reachable\": %s, \"claim_id\": ", host->machine_guid, + (host->receiver || host == localhost) ? "true" : "false"); + netdata_mutex_unlock(&host->receiver_lock); + + netdata_mutex_lock(&host->claimed_id_lock); + if (host->claimed_id) + buffer_sprintf(wb, "\"%s\" }", host->claimed_id); + else + buffer_strcat(wb, "null }"); + netdata_mutex_unlock(&host->claimed_id_lock); + count++; } - buffer_strcat(wb, "\n"); rrd_unlock(); + + buffer_strcat(wb, "\n\t],\n"); } inline void host_labels2json(RRDHOST *host, BUFFER *wb, size_t indentation) { @@ -825,9 +855,7 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) buffer_sprintf(wb, "\t\"version\": \"%s\",\n", host->program_version); buffer_sprintf(wb, "\t\"uid\": \"%s\",\n", host->machine_guid); - buffer_strcat(wb, "\t\"mirrored_hosts\": [\n"); web_client_api_request_v1_info_mirrored_hosts(wb); - buffer_strcat(wb, "\t],\n"); buffer_strcat(wb, "\t\"alarms\": {\n"); web_client_api_request_v1_info_summary_alarm_statuses(host, wb); |