diff options
author | vkalintiris <vasilis@netdata.cloud> | 2021-12-22 17:13:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-22 17:13:45 +0200 |
commit | 5049de8f7a132205b32f2c523998f93cbbfc0481 (patch) | |
tree | 452a81eadda2ac3354bc5ceff0d529e47520c578 /web | |
parent | df8930ddd370b2a9fec96b1cbb45e8ae530c0aad (diff) |
Provide runtime ml info from a new endpoint. (#11886)
* Provide runtime ml info from a new endpoint.
* Add hosts & charts to skip from ML in the /info endpoint.
This information belongs in /info, and not in /ml-info, because the
value of these variables can not change at the agent's runtime.
* Use strdupz instead of strdup.
Diffstat (limited to 'web')
-rw-r--r-- | web/api/web_api_v1.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index d335dd687d..ff5af93b32 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -1130,11 +1130,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 +1174,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 +1190,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 +1271,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 }, |