summaryrefslogtreecommitdiffstats
path: root/ml/ml.cc
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2022-10-05 10:11:12 +0300
committerGitHub <noreply@github.com>2022-10-05 10:11:12 +0300
commit6850878e697d66dc90b9af1e750b22238c63c292 (patch)
tree1e4bf33a393c258ac31bf6971f1ea2b246e1635c /ml/ml.cc
parent2b7a964d49df6deda32bffbe6141ec53429d68fd (diff)
Remove anomaly detector (#13657)
* Move all dims under one class. * Dimension owns anomaly rate RD. * Remove Dimension::isAnomalous() * Remove Dimension::trainEvery() * Rm ml/kmeans * Remove anomaly detector The same logic can be implemented by using the host anomaly rate dim. * Profile plugin. * Revert "Profile plugin." This reverts commit e3db37cb49c514502c5216cfe7bca2a003fb90f1. * Add separate source files for anomaly detection charts. * Handle training/prediction sync at the dimension level. * Keep multiple KMeans models in mem. * Move feature extraction outside KMeans class. * Use multiple models. * Add /api/v1/ml_models endpoint. * Remove Dimension::getID() * Use just 1 model and fix tests. * Add detection logic based on rrdr. * Remove config options related to anomaly detection. * Make anomaly detection queries configurable. * Fix ad query duration option. * Finalize queries in all code paths. * Check if query was initialized before finalizing it * Do not leak OWA * Profile plugin. * Revert "Profile plugin." This reverts commit 5c77145d0df7e091d030476c480ab8d9cbceb89e. * Change context from anomaly_detection to detector_events.
Diffstat (limited to 'ml/ml.cc')
-rw-r--r--ml/ml.cc61
1 files changed, 13 insertions, 48 deletions
diff --git a/ml/ml.cc b/ml/ml.cc
index a7111312eb..60ea8d60cb 100644
--- a/ml/ml.cc
+++ b/ml/ml.cc
@@ -82,7 +82,7 @@ void ml_new_dimension(RRDDIM *RD) {
if (rrdset_is_ar_chart(RS))
return;
- Dimension *D = new Dimension(RD);
+ Dimension *D = new Dimension(RD, H->getAnomalyRateRS());
RD->ml_dimension = static_cast<ml_dimension_t>(D);
H->addDimension(D);
}
@@ -127,59 +127,24 @@ char *ml_get_host_runtime_info(RRDHOST *RH) {
return strdup(ConfigJson.dump(1, '\t').c_str());
}
-bool ml_is_anomalous(RRDDIM *RD, double Value, bool Exists) {
- Dimension *D = static_cast<Dimension *>(RD->ml_dimension);
- if (!D)
- return false;
-
- D->addValue(Value, Exists);
- bool Result = D->predict().second;
- return Result;
-}
+char *ml_get_host_models(RRDHOST *RH) {
+ nlohmann::json ModelsJson;
-char *ml_get_anomaly_events(RRDHOST *RH, const char *AnomalyDetectorName,
- int AnomalyDetectorVersion, time_t After, time_t Before) {
- if (!RH || !RH->ml_host) {
- error("No host");
- return nullptr;
- }
-
- Host *H = static_cast<Host *>(RH->ml_host);
- std::vector<std::pair<time_t, time_t>> TimeRanges;
-
- bool Res = H->getAnomaliesInRange(TimeRanges, AnomalyDetectorName,
- AnomalyDetectorVersion,
- H->getUUID(),
- After, Before);
- if (!Res) {
- error("DB result is empty");
- return nullptr;
+ if (RH && RH->ml_host) {
+ Host *H = static_cast<Host *>(RH->ml_host);
+ H->getModelsAsJson(ModelsJson);
+ return strdup(ModelsJson.dump(2, '\t').c_str());
}
- nlohmann::json Json = TimeRanges;
- return strdup(Json.dump(4).c_str());
+ return nullptr;
}
-char *ml_get_anomaly_event_info(RRDHOST *RH, const char *AnomalyDetectorName,
- int AnomalyDetectorVersion, time_t After, time_t Before) {
- if (!RH || !RH->ml_host) {
- error("No host");
- return nullptr;
- }
-
- Host *H = static_cast<Host *>(RH->ml_host);
-
- nlohmann::json Json;
- bool Res = H->getAnomalyInfo(Json, AnomalyDetectorName,
- AnomalyDetectorVersion,
- H->getUUID(),
- After, Before);
- if (!Res) {
- error("DB result is empty");
- return nullptr;
- }
+bool ml_is_anomalous(RRDDIM *RD, double Value, bool Exists) {
+ Dimension *D = static_cast<Dimension *>(RD->ml_dimension);
+ if (!D)
+ return false;
- return strdup(Json.dump(4, '\t').c_str());
+ return D->predict(Value, Exists);
}
void ml_process_rrdr(RRDR *R, int MaxAnomalyRates) {