diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-01-26 18:05:15 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-01-26 18:05:42 +0000 |
commit | 112b5b91647c3dea45cc1c9bc364df526c8012f1 (patch) | |
tree | 450af925135ec664c4310a1eb28b69481094ee2a /web/api | |
parent | Releasing debian version 1.32.1-2. (diff) | |
download | netdata-112b5b91647c3dea45cc1c9bc364df526c8012f1.tar.xz netdata-112b5b91647c3dea45cc1c9bc364df526c8012f1.zip |
Merging upstream version 1.33.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/api')
-rw-r--r-- | web/api/exporters/shell/allmetrics_shell.c | 51 | ||||
-rw-r--r-- | web/api/formatters/rrdset2json.c | 90 | ||||
-rw-r--r-- | web/api/web_api_v1.c | 80 |
3 files changed, 128 insertions, 93 deletions
diff --git a/web/api/exporters/shell/allmetrics_shell.c b/web/api/exporters/shell/allmetrics_shell.c index 0b0ce2291..0cbaf3069 100644 --- a/web/api/exporters/shell/allmetrics_shell.c +++ b/web/api/exporters/shell/allmetrics_shell.c @@ -107,22 +107,23 @@ void rrd_stats_api_v1_charts_allmetrics_json(RRDHOST *host, BUFFER *wb) { if(rrdset_is_available_for_viewers(st)) { rrdset_rdlock(st); - buffer_sprintf(wb, "%s\n" - "\t\"%s\": {\n" - "\t\t\"name\":\"%s\",\n" - "\t\t\"family\":\"%s\",\n" - "\t\t\"context\":\"%s\",\n" - "\t\t\"units\":\"%s\",\n" - "\t\t\"last_updated\": %ld,\n" - "\t\t\"dimensions\": {" - , chart_counter?",":"" - , st->id - , st->name - , st->family - , st->context - , st->units - , rrdset_last_entry_t_nolock(st) - ); + buffer_sprintf( + wb, + "%s\n" + "\t\"%s\": {\n" + "\t\t\"name\":\"%s\",\n" + "\t\t\"family\":\"%s\",\n" + "\t\t\"context\":\"%s\",\n" + "\t\t\"units\":\"%s\",\n" + "\t\t\"last_updated\": %"PRId64",\n" + "\t\t\"dimensions\": {", + chart_counter ? "," : "", + st->id, + st->name, + st->family, + st->context, + st->units, + (int64_t)rrdset_last_entry_t_nolock(st)); chart_counter++; dimension_counter = 0; @@ -131,15 +132,15 @@ void rrd_stats_api_v1_charts_allmetrics_json(RRDHOST *host, BUFFER *wb) { RRDDIM *rd; rrddim_foreach_read(rd, st) { if(rd->collections_counter && !rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) { - - buffer_sprintf(wb, "%s\n" - "\t\t\t\"%s\": {\n" - "\t\t\t\t\"name\": \"%s\",\n" - "\t\t\t\t\"value\": " - , dimension_counter?",":"" - , rd->id - , rd->name - ); + buffer_sprintf( + wb, + "%s\n" + "\t\t\t\"%s\": {\n" + "\t\t\t\t\"name\": \"%s\",\n" + "\t\t\t\t\"value\": ", + dimension_counter ? "," : "", + rd->id, + rd->name); if(isnan(rd->last_stored_value)) buffer_strcat(wb, "null"); diff --git a/web/api/formatters/rrdset2json.c b/web/api/formatters/rrdset2json.c index 5482881e0..ce237ab23 100644 --- a/web/api/formatters/rrdset2json.c +++ b/web/api/formatters/rrdset2json.c @@ -40,58 +40,62 @@ void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memor time_t first_entry_t = rrdset_first_entry_t_nolock(st); time_t last_entry_t = rrdset_last_entry_t_nolock(st); - buffer_sprintf(wb, - "\t\t{\n" - "\t\t\t\"id\": \"%s\",\n" - "\t\t\t\"name\": \"%s\",\n" - "\t\t\t\"type\": \"%s\",\n" - "\t\t\t\"family\": \"%s\",\n" - "\t\t\t\"context\": \"%s\",\n" - "\t\t\t\"title\": \"%s (%s)\",\n" - "\t\t\t\"priority\": %ld,\n" - "\t\t\t\"plugin\": \"%s\",\n" - "\t\t\t\"module\": \"%s\",\n" - "\t\t\t\"enabled\": %s,\n" - "\t\t\t\"units\": \"%s\",\n" - "\t\t\t\"data_url\": \"/api/v1/data?chart=%s\",\n" - "\t\t\t\"chart_type\": \"%s\",\n" - , st->id - , st->name - , st->type - , st->family - , st->context - , st->title, st->name - , st->priority - , st->plugin_name?st->plugin_name:"" - , st->module_name?st->module_name:"" - , rrdset_flag_check(st, RRDSET_FLAG_ENABLED)?"true":"false" - , st->units - , st->name - , rrdset_type_name(st->chart_type) - ); + buffer_sprintf( + wb, + "\t\t{\n" + "\t\t\t\"id\": \"%s\",\n" + "\t\t\t\"name\": \"%s\",\n" + "\t\t\t\"type\": \"%s\",\n" + "\t\t\t\"family\": \"%s\",\n" + "\t\t\t\"context\": \"%s\",\n" + "\t\t\t\"title\": \"%s (%s)\",\n" + "\t\t\t\"priority\": %ld,\n" + "\t\t\t\"plugin\": \"%s\",\n" + "\t\t\t\"module\": \"%s\",\n" + "\t\t\t\"enabled\": %s,\n" + "\t\t\t\"units\": \"%s\",\n" + "\t\t\t\"data_url\": \"/api/v1/data?chart=%s\",\n" + "\t\t\t\"chart_type\": \"%s\",\n", + st->id, + st->name, + st->type, + st->family, + st->context, + st->title, + st->name, + st->priority, + st->plugin_name ? st->plugin_name : "", + st->module_name ? st->module_name : "", + rrdset_flag_check(st, RRDSET_FLAG_ENABLED) ? "true" : "false", + st->units, + st->name, + rrdset_type_name(st->chart_type)); if (likely(!skip_volatile)) - buffer_sprintf(wb, - "\t\t\t\"duration\": %ld,\n" - , last_entry_t - first_entry_t + st->update_every//st->entries * st->update_every + buffer_sprintf( + wb, + "\t\t\t\"duration\": %"PRId64",\n", + (int64_t)(last_entry_t - first_entry_t + st->update_every) //st->entries * st->update_every ); - buffer_sprintf(wb, - "\t\t\t\"first_entry\": %ld,\n" - , first_entry_t //rrdset_first_entry_t(st) + buffer_sprintf( + wb, + "\t\t\t\"first_entry\": %"PRId64",\n", + (int64_t)first_entry_t //rrdset_first_entry_t(st) ); if (likely(!skip_volatile)) - buffer_sprintf(wb, - "\t\t\t\"last_entry\": %ld,\n" - , last_entry_t//rrdset_last_entry_t(st) + buffer_sprintf( + wb, + "\t\t\t\"last_entry\": %"PRId64",\n", + (int64_t)last_entry_t //rrdset_last_entry_t(st) ); - buffer_sprintf(wb, - "\t\t\t\"update_every\": %d,\n" - "\t\t\t\"dimensions\": {\n" - , st->update_every - ); + buffer_sprintf( + wb, + "\t\t\t\"update_every\": %d,\n" + "\t\t\t\"dimensions\": {\n", + st->update_every); unsigned long memory = st->memsize; diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index d335dd687..6361f9970 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -3,6 +3,7 @@ #include "web_api_v1.h" char *api_secret; +extern int aclk_use_new_cloud_arch; static struct { const char *name; @@ -589,9 +590,13 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c w->id, google_version, google_reqId, google_sig, google_out, responseHandler, outFileName ); - buffer_sprintf(w->response.data, - "%s({version:'%s',reqId:'%s',status:'ok',sig:'%ld',table:", - responseHandler, google_version, google_reqId, st->last_updated.tv_sec); + buffer_sprintf( + w->response.data, + "%s({version:'%s',reqId:'%s',status:'ok',sig:'%"PRId64"',table:", + responseHandler, + google_version, + google_reqId, + (int64_t)st->last_updated.tv_sec); } else if(format == DATASOURCE_JSONP) { if(responseHandler == NULL) @@ -980,30 +985,18 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) #ifdef ENABLE_ACLK buffer_strcat(wb, "\t\"cloud-available\": true,\n"); -#ifdef ACLK_NG buffer_strcat(wb, "\t\"aclk-ng-available\": true,\n"); -#else - buffer_strcat(wb, "\t\"aclk-ng-available\": false,\n"); -#endif -#if defined(ACLK_NG) && defined(ENABLE_NEW_CLOUD_PROTOCOL) +#ifdef ENABLE_NEW_CLOUD_PROTOCOL buffer_strcat(wb, "\t\"aclk-ng-new-cloud-protocol\": true,\n"); #else buffer_strcat(wb, "\t\"aclk-ng-new-cloud-protocol\": false,\n"); #endif -#ifdef ACLK_LEGACY - buffer_strcat(wb, "\t\"aclk-legacy-available\": true,\n"); -#else buffer_strcat(wb, "\t\"aclk-legacy-available\": false,\n"); -#endif - buffer_strcat(wb, "\t\"aclk-implementation\": \""); - if (aclk_ng) { - buffer_strcat(wb, "Next Generation"); - } else { - buffer_strcat(wb, "legacy"); - } - buffer_strcat(wb, "\",\n"); + buffer_strcat(wb, "\t\"aclk-implementation\": \"Next Generation\",\n"); #else buffer_strcat(wb, "\t\"cloud-available\": false,\n"); + buffer_strcat(wb, "\t\"aclk-ng-available\": false,\n"); + buffer_strcat(wb, "\t\"aclk-legacy-available\": false,\n"); #endif char *agent_id = is_agent_claimed(); if (agent_id == NULL) @@ -1013,11 +1006,18 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) freez(agent_id); } #ifdef ENABLE_ACLK - if (aclk_connected) + if (aclk_connected) { buffer_strcat(wb, "\t\"aclk-available\": true,\n"); +#ifdef ENABLE_NEW_CLOUD_PROTOCOL + if (aclk_use_new_cloud_arch) + buffer_strcat(wb, "\t\"aclk-available-protocol\": \"New\",\n"); + else +#endif + buffer_strcat(wb, "\t\"aclk-available-protocol\": \"Legacy\",\n"); + } else #endif - buffer_strcat(wb, "\t\"aclk-available\": false,\n"); // Intentionally valid with/without #ifdef above + buffer_strcat(wb, "\t\"aclk-available\": false,\n\t\"aclk-available-protocol\": null,\n"); // Intentionally valid with/without #ifdef above buffer_strcat(wb, "\t\"memory-mode\": "); analytics_get_data(analytics_data.netdata_config_memory_mode, wb); @@ -1035,6 +1035,14 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) analytics_get_data(analytics_data.netdata_config_stream_enabled, wb); buffer_strcat(wb, ",\n"); +#ifdef ENABLE_COMPRESSION + buffer_strcat(wb, "\t\"stream-compression\": "); + buffer_strcat(wb, (default_compression_enabled ? "\"enabled\"" : "\"disabled\"")); + buffer_strcat(wb, ",\n"); +#else + buffer_strcat(wb, "\t\"stream-compression\": \"N/A\",\n"); +#endif //ENABLE_COMPRESSION + buffer_strcat(wb, "\t\"hosts-available\": "); analytics_get_data(analytics_data.netdata_config_hosts_available, wb); buffer_strcat(wb, ",\n"); @@ -1130,11 +1138,11 @@ int web_client_api_request_v1_anomaly_events(RRDHOST *host, struct web_client *w char *s; if (!before || !after) - s = strdup("{\"error\": \"missing after/before parameters\" }\n"); + s = strdupz("{\"error\": \"missing after/before parameters\" }\n"); else { s = ml_get_anomaly_events(host, "AD1", 1, after, before); if (!s) - s = strdup("{\"error\": \"json string is empty\" }\n"); + s = strdupz("{\"error\": \"json string is empty\" }\n"); } BUFFER *wb = w->response.data; @@ -1174,11 +1182,11 @@ int web_client_api_request_v1_anomaly_event_info(RRDHOST *host, struct web_clien char *s; if (!before || !after) - s = strdup("{\"error\": \"missing after/before parameters\" }\n"); + s = strdupz("{\"error\": \"missing after/before parameters\" }\n"); else { s = ml_get_anomaly_event_info(host, "AD1", 1, after, before); if (!s) - s = strdup("{\"error\": \"json string is empty\" }\n"); + s = strdupz("{\"error\": \"json string is empty\" }\n"); } BUFFER *wb = w->response.data; @@ -1190,6 +1198,27 @@ int web_client_api_request_v1_anomaly_event_info(RRDHOST *host, struct web_clien freez(s); return HTTP_RESP_OK; } + +int web_client_api_request_v1_ml_info(RRDHOST *host, struct web_client *w, char *url) { + (void) url; + + if (!netdata_ready) + return HTTP_RESP_BACKEND_FETCH_FAILED; + + char *s = ml_get_host_runtime_info(host); + if (!s) + s = strdupz("{\"error\": \"json string is empty\" }\n"); + + BUFFER *wb = w->response.data; + buffer_flush(wb); + wb->contenttype = CT_APPLICATION_JSON; + buffer_strcat(wb, s); + buffer_no_cacheable(wb); + + freez(s); + return HTTP_RESP_OK; +} + #endif // defined(ENABLE_ML) inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, char *url) { @@ -1250,6 +1279,7 @@ static struct api_command { #if defined(ENABLE_ML) { "anomaly_events", 0, WEB_CLIENT_ACL_DASHBOARD, web_client_api_request_v1_anomaly_events }, { "anomaly_event_info", 0, WEB_CLIENT_ACL_DASHBOARD, web_client_api_request_v1_anomaly_event_info }, + { "ml_info", 0, WEB_CLIENT_ACL_DASHBOARD, web_client_api_request_v1_ml_info }, #endif { "manage/health", 0, WEB_CLIENT_ACL_MGMT, web_client_api_request_v1_mgmt_health }, |