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 /ml | |
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 'ml')
-rw-r--r-- | ml/Config.cc | 14 | ||||
-rw-r--r-- | ml/Config.h | 3 | ||||
-rw-r--r-- | ml/Host.cc | 4 | ||||
-rw-r--r-- | ml/ml.cc | 14 | ||||
-rw-r--r-- | ml/ml.h | 1 |
5 files changed, 28 insertions, 8 deletions
diff --git a/ml/Config.cc b/ml/Config.cc index f48f9b39fb..df0a2825e3 100644 --- a/ml/Config.cc +++ b/ml/Config.cc @@ -47,12 +47,6 @@ void Config::readMLConfig(void) { double ADWindowRateThreshold = config_get_float(ConfigSectionML, "window minimum anomaly rate", 0.25); double ADDimensionRateThreshold = config_get_float(ConfigSectionML, "anomaly event min dimension rate threshold", 0.05); - std::string HostsToSkip = config_get(ConfigSectionML, "hosts to skip from training", "!*"); - std::string ChartsToSkip = config_get(ConfigSectionML, "charts to skip from training", - "!system.* !cpu.* !mem.* !disk.* !disk_* " - "!ip.* !ipv4.* !ipv6.* !net.* !net_* !netfilter.* " - "!services.* !apps.* !groups.* !user.* !ebpf.* !netdata.* *"); - std::stringstream SS; SS << netdata_configured_cache_dir << "/anomaly-detection.db"; Cfg.AnomalyDBPath = SS.str(); @@ -123,6 +117,12 @@ void Config::readMLConfig(void) { Cfg.ADWindowRateThreshold = ADWindowRateThreshold; Cfg.ADDimensionRateThreshold = ADDimensionRateThreshold; - Cfg.SP_HostsToSkip = simple_pattern_create(HostsToSkip.c_str(), NULL, SIMPLE_PATTERN_EXACT); + Cfg.HostsToSkip = config_get(ConfigSectionML, "hosts to skip from training", "!*"); + Cfg.SP_HostsToSkip = simple_pattern_create(Cfg.HostsToSkip.c_str(), NULL, SIMPLE_PATTERN_EXACT); + + Cfg.ChartsToSkip = config_get(ConfigSectionML, "charts to skip from training", + "!system.* !cpu.* !mem.* !disk.* !disk_* " + "!ip.* !ipv4.* !ipv6.* !net.* !net_* !netfilter.* " + "!services.* !apps.* !groups.* !user.* !ebpf.* !netdata.* *"); Cfg.SP_ChartsToSkip = simple_pattern_create(ChartsToSkip.c_str(), NULL, SIMPLE_PATTERN_EXACT); } diff --git a/ml/Config.h b/ml/Config.h index f29bae3a60..58ecce53f3 100644 --- a/ml/Config.h +++ b/ml/Config.h @@ -30,7 +30,10 @@ public: double ADWindowRateThreshold; double ADDimensionRateThreshold; + std::string HostsToSkip; SIMPLE_PATTERN *SP_HostsToSkip; + + std::string ChartsToSkip; SIMPLE_PATTERN *SP_ChartsToSkip; std::string AnomalyDBPath; diff --git a/ml/Host.cc b/ml/Host.cc index d26ff2ae40..b632710a44 100644 --- a/ml/Host.cc +++ b/ml/Host.cc @@ -282,6 +282,9 @@ void RrdHost::getConfigAsJson(nlohmann::json &Json) const { Json["idle-window-size"] = Cfg.ADIdleWindowSize; Json["window-rate-threshold"] = Cfg.ADWindowRateThreshold; Json["dimension-rate-threshold"] = Cfg.ADDimensionRateThreshold; + + Json["hosts-to-skip"] = Cfg.HostsToSkip; + Json["charts-to-skip"] = Cfg.ChartsToSkip; } std::pair<Dimension *, Duration<double>> @@ -441,6 +444,7 @@ void DetectableHost::detect() { } void DetectableHost::getDetectionInfoAsJson(nlohmann::json &Json) const { + Json["version"] = 1; Json["anomalous-dimensions"] = NumAnomalousDimensions; Json["normal-dimensions"] = NumNormalDimensions; Json["total-dimensions"] = NumAnomalousDimensions + NumNormalDimensions; @@ -75,7 +75,6 @@ char *ml_get_host_info(RRDHOST *RH) { if (RH && RH->ml_host) { Host *H = static_cast<Host *>(RH->ml_host); H->getConfigAsJson(ConfigJson); - H->getDetectionInfoAsJson(ConfigJson); } else { ConfigJson["enabled"] = false; } @@ -83,6 +82,19 @@ char *ml_get_host_info(RRDHOST *RH) { return strdup(ConfigJson.dump(2, '\t').c_str()); } +char *ml_get_host_runtime_info(RRDHOST *RH) { + nlohmann::json ConfigJson; + + if (RH && RH->ml_host) { + Host *H = static_cast<Host *>(RH->ml_host); + H->getDetectionInfoAsJson(ConfigJson); + } else { + return nullptr; + } + + return strdup(ConfigJson.dump(1, '\t').c_str()); +} + bool ml_is_anomalous(RRDDIM *RD, double Value, bool Exists) { Dimension *D = static_cast<Dimension *>(RD->state->ml_dimension); if (!D) @@ -18,6 +18,7 @@ void ml_new_host(RRDHOST *RH); void ml_delete_host(RRDHOST *RH); char *ml_get_host_info(RRDHOST *RH); +char *ml_get_host_runtime_info(RRDHOST *RH); void ml_new_dimension(RRDDIM *RD); void ml_delete_dimension(RRDDIM *RD); |