diff options
Diffstat (limited to 'ml')
-rw-r--r-- | ml/Config.cc | 3 | ||||
-rw-r--r-- | ml/Config.h | 2 | ||||
-rw-r--r-- | ml/Host.cc | 34 | ||||
-rw-r--r-- | ml/Host.h | 2 | ||||
-rw-r--r-- | ml/ml-dummy.c | 4 | ||||
-rw-r--r-- | ml/ml.cc | 10 | ||||
-rw-r--r-- | ml/ml.h | 2 |
7 files changed, 27 insertions, 30 deletions
diff --git a/ml/Config.cc b/ml/Config.cc index ba3a614452..cdc43d1655 100644 --- a/ml/Config.cc +++ b/ml/Config.cc @@ -99,7 +99,8 @@ void Config::readMLConfig(void) { Cfg.DimensionAnomalyScoreThreshold = DimensionAnomalyScoreThreshold; Cfg.HostAnomalyRateThreshold = HostAnomalyRateThreshold; - Cfg.AnomalyDetectionGroupingMethod = web_client_api_request_v1_data_group(AnomalyDetectionGroupingMethod.c_str(), RRDR_GROUPING_AVERAGE); + Cfg.AnomalyDetectionGroupingMethod = time_grouping_parse( + AnomalyDetectionGroupingMethod.c_str(), RRDR_GROUPING_AVERAGE); Cfg.AnomalyDetectionQueryDuration = AnomalyDetectionQueryDuration; Cfg.HostsToSkip = config_get(ConfigSectionML, "hosts to skip from training", "!*"); diff --git a/ml/Config.h b/ml/Config.h index f10e114926..26ceaf3004 100644 --- a/ml/Config.h +++ b/ml/Config.h @@ -29,7 +29,7 @@ public: double DimensionAnomalyScoreThreshold; double HostAnomalyRateThreshold; - RRDR_GROUPING AnomalyDetectionGroupingMethod; + RRDR_TIME_GROUPING AnomalyDetectionGroupingMethod; time_t AnomalyDetectionQueryDuration; bool StreamADCharts; diff --git a/ml/Host.cc b/ml/Host.cc index a5f276a807..e22580be9a 100644 --- a/ml/Host.cc +++ b/ml/Host.cc @@ -19,30 +19,30 @@ void Host::removeChart(Chart *C) { Charts.erase(C->getRS()); } -void Host::getConfigAsJson(nlohmann::json &Json) const { - Json["version"] = 1; +void Host::getConfigAsJson(BUFFER *wb) const { + buffer_json_member_add_uint64(wb, "version", 1); - Json["enabled"] = Cfg.EnableAnomalyDetection; + buffer_json_member_add_boolean(wb, "enabled", Cfg.EnableAnomalyDetection); - Json["min-train-samples"] = Cfg.MinTrainSamples; - Json["max-train-samples"] = Cfg.MaxTrainSamples; - Json["train-every"] = Cfg.TrainEvery; + buffer_json_member_add_uint64(wb, "min-train-samples", Cfg.MinTrainSamples); + buffer_json_member_add_uint64(wb, "max-train-samples", Cfg.MaxTrainSamples); + buffer_json_member_add_uint64(wb, "train-every", Cfg.TrainEvery); - Json["diff-n"] = Cfg.DiffN; - Json["smooth-n"] = Cfg.SmoothN; - Json["lag-n"] = Cfg.LagN; + buffer_json_member_add_uint64(wb, "diff-n", Cfg.DiffN); + buffer_json_member_add_uint64(wb, "smooth-n", Cfg.SmoothN); + buffer_json_member_add_uint64(wb, "lag-n", Cfg.LagN); - Json["random-sampling-ratio"] = Cfg.RandomSamplingRatio; - Json["max-kmeans-iters"] = Cfg.MaxKMeansIters; + buffer_json_member_add_double(wb, "random-sampling-ratio", Cfg.RandomSamplingRatio); + buffer_json_member_add_uint64(wb, "max-kmeans-iters", Cfg.MaxKMeansIters); - Json["dimension-anomaly-score-threshold"] = Cfg.DimensionAnomalyScoreThreshold; + buffer_json_member_add_double(wb, "dimension-anomaly-score-threshold", Cfg.DimensionAnomalyScoreThreshold); - Json["host-anomaly-rate-threshold"] = Cfg.HostAnomalyRateThreshold; - Json["anomaly-detection-grouping-method"] = group_method2string(Cfg.AnomalyDetectionGroupingMethod); - Json["anomaly-detection-query-duration"] = Cfg.AnomalyDetectionQueryDuration; + buffer_json_member_add_double(wb, "host-anomaly-rate-threshold", Cfg.HostAnomalyRateThreshold); + buffer_json_member_add_string(wb, "anomaly-detection-grouping-method", time_grouping_method2string(Cfg.AnomalyDetectionGroupingMethod)); + buffer_json_member_add_time_t(wb, "anomaly-detection-query-duration", Cfg.AnomalyDetectionQueryDuration); - Json["hosts-to-skip"] = Cfg.HostsToSkip; - Json["charts-to-skip"] = Cfg.ChartsToSkip; + buffer_json_member_add_string(wb, "hosts-to-skip", Cfg.HostsToSkip.c_str()); + buffer_json_member_add_string(wb, "charts-to-skip", Cfg.ChartsToSkip.c_str()); } void Host::getModelsAsJson(nlohmann::json &Json) { @@ -34,7 +34,7 @@ public: void addChart(Chart *C); void removeChart(Chart *C); - void getConfigAsJson(nlohmann::json &Json) const; + void getConfigAsJson(BUFFER *wb) const; void getModelsAsJson(nlohmann::json &Json); void getDetectionInfoAsJson(nlohmann::json &Json) const; diff --git a/ml/ml-dummy.c b/ml/ml-dummy.c index 966602d2c8..c3dcb93370 100644 --- a/ml/ml-dummy.c +++ b/ml/ml-dummy.c @@ -47,9 +47,9 @@ void ml_stop_anomaly_detection_threads(RRDHOST *RH) { UNUSED(RH); } -char *ml_get_host_info(RRDHOST *RH) { +void ml_get_host_info(RRDHOST *RH, BUFFER *wb) { (void) RH; - return NULL; + (void) wb; } char *ml_get_host_runtime_info(RRDHOST *RH) { @@ -108,17 +108,13 @@ void ml_dimension_delete(RRDDIM *RD) { RD->ml_dimension = nullptr; } -char *ml_get_host_info(RRDHOST *RH) { - nlohmann::json ConfigJson; - +void ml_get_host_info(RRDHOST *RH, BUFFER *wb) { if (RH && RH->ml_host) { Host *H = reinterpret_cast<Host *>(RH->ml_host); - H->getConfigAsJson(ConfigJson); + H->getConfigAsJson(wb); } else { - ConfigJson["enabled"] = false; + buffer_json_member_add_boolean(wb, "enabled", false); } - - return strdupz(ConfigJson.dump(2, '\t').c_str()); } char *ml_get_host_runtime_info(RRDHOST *RH) { @@ -33,7 +33,7 @@ void ml_start_anomaly_detection_threads(RRDHOST *RH); void ml_stop_anomaly_detection_threads(RRDHOST *RH); void ml_cancel_anomaly_detection_threads(RRDHOST *RH); -char *ml_get_host_info(RRDHOST *RH); +void ml_get_host_info(RRDHOST *RH, BUFFER *wb); char *ml_get_host_runtime_info(RRDHOST *RH); char *ml_get_host_models(RRDHOST *RH); |