From 112b5b91647c3dea45cc1c9bc364df526c8012f1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 26 Jan 2022 19:05:15 +0100 Subject: Merging upstream version 1.33.0. Signed-off-by: Daniel Baumann --- ml/Config.cc | 14 +++++++------- ml/Config.h | 3 +++ ml/Host.cc | 4 ++++ ml/kmeans/SamplesBuffer.h | 5 +++-- ml/ml-dummy.c | 5 ++++- ml/ml.cc | 14 +++++++++++++- ml/ml.h | 1 + 7 files changed, 35 insertions(+), 11 deletions(-) (limited to 'ml') diff --git a/ml/Config.cc b/ml/Config.cc index f48f9b39f..df0a2825e 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 f29bae3a6..58ecce53f 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 d26ff2ae4..b632710a4 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> @@ -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; diff --git a/ml/kmeans/SamplesBuffer.h b/ml/kmeans/SamplesBuffer.h index fccd216d5..5c3cb1a97 100644 --- a/ml/kmeans/SamplesBuffer.h +++ b/ml/kmeans/SamplesBuffer.h @@ -20,8 +20,9 @@ public: Sample(CalculatedNumber *Buf, size_t N) : CNs(Buf), NumDims(N) {} void initDSample(DSample &DS) const { - for (size_t Idx = 0; Idx != NumDims; Idx++) - DS(Idx) = CNs[Idx]; + for (size_t Idx = 0; Idx != NumDims; Idx++) { + DS(Idx) = std::abs(CNs[Idx]); + } } void add(const Sample &RHS) const { diff --git a/ml/ml-dummy.c b/ml/ml-dummy.c index 795b80c34..222f0b0f6 100644 --- a/ml/ml-dummy.c +++ b/ml/ml-dummy.c @@ -10,7 +10,10 @@ void ml_new_host(RRDHOST *RH) { (void) RH; } void ml_delete_host(RRDHOST *RH) { (void) RH; } -char *ml_get_host_info(RRDHOST *RH) { (void) RH; } +char *ml_get_host_info(RRDHOST *RH) { + (void) RH; + return NULL; +} void ml_new_dimension(RRDDIM *RD) { (void) RD; } diff --git a/ml/ml.cc b/ml/ml.cc index 857d23d33..cfda3d28f 100644 --- a/ml/ml.cc +++ b/ml/ml.cc @@ -75,7 +75,6 @@ char *ml_get_host_info(RRDHOST *RH) { if (RH && RH->ml_host) { Host *H = static_cast(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(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(RD->state->ml_dimension); if (!D) diff --git a/ml/ml.h b/ml/ml.h index 96448453c..783bfabb9 100644 --- a/ml/ml.h +++ b/ml/ml.h @@ -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); -- cgit v1.2.3