diff options
Diffstat (limited to '')
-rw-r--r-- | src/ml/ml.cc (renamed from ml/ml.cc) | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/ml/ml.cc b/src/ml/ml.cc index 5f8f5033e..33a01f2c6 100644 --- a/ml/ml.cc +++ b/src/ml/ml.cc @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#include <dlib/clustering.h> +#include "dlib/dlib/clustering.h" #include "ml-private.h" @@ -358,7 +358,7 @@ ml_dimension_calculated_numbers(ml_training_thread_t *training_thread, ml_dimens */ struct storage_engine_query_handle handle; - storage_engine_query_init(dim->rd->tiers[0].backend, dim->rd->tiers[0].db_metric_handle, &handle, + storage_engine_query_init(dim->rd->tiers[0].seb, dim->rd->tiers[0].smh, &handle, training_response.query_after_t, training_response.query_before_t, STORAGE_PRIORITY_BEST_EFFORT); @@ -1090,20 +1090,24 @@ ml_host_detect_once(ml_host_t *host) host->mls.num_anomalous_dimensions += chart_mls.num_anomalous_dimensions; host->mls.num_normal_dimensions += chart_mls.num_normal_dimensions; - STRING *key = rs->parts.type; - auto &um = host->type_anomaly_rate; - auto it = um.find(key); - if (it == um.end()) { - um[key] = ml_type_anomaly_rate_t { - .rd = NULL, - .normal_dimensions = 0, - .anomalous_dimensions = 0 - }; - it = um.find(key); - } + if (spinlock_trylock_cancelable(&host->type_anomaly_rate_spinlock)) + { + STRING *key = rs->parts.type; + auto &um = host->type_anomaly_rate; + auto it = um.find(key); + if (it == um.end()) { + um[key] = ml_type_anomaly_rate_t { + .rd = NULL, + .normal_dimensions = 0, + .anomalous_dimensions = 0 + }; + it = um.find(key); + } - it->second.anomalous_dimensions += chart_mls.num_anomalous_dimensions; - it->second.normal_dimensions += chart_mls.num_normal_dimensions; + it->second.anomalous_dimensions += chart_mls.num_anomalous_dimensions; + it->second.normal_dimensions += chart_mls.num_normal_dimensions; + spinlock_unlock_cancelable(&host->type_anomaly_rate_spinlock); + } } rrdset_foreach_done(rsp); @@ -1310,6 +1314,7 @@ void ml_host_new(RRDHOST *rh) host->training_queue = Cfg.training_threads[times_called++ % Cfg.num_training_threads].training_queue; netdata_mutex_init(&host->mutex); + spinlock_init(&host->type_anomaly_rate_spinlock); host->ml_running = true; rh->ml_host = (rrd_ml_host_t *) host; @@ -1416,8 +1421,7 @@ void ml_host_get_info(RRDHOST *rh, BUFFER *wb) buffer_json_member_add_double(wb, "dimension-anomaly-score-threshold", Cfg.dimension_anomaly_score_threshold); - buffer_json_member_add_string(wb, "anomaly-detection-grouping-method", - time_grouping_method2string(Cfg.anomaly_detection_grouping_method)); + buffer_json_member_add_string(wb, "anomaly-detection-grouping-method", time_grouping_id2txt(Cfg.anomaly_detection_grouping_method)); buffer_json_member_add_int64(wb, "anomaly-detection-query-duration", Cfg.anomaly_detection_query_duration); @@ -1787,7 +1791,7 @@ void ml_init() // create table if (db) { int target_version = perform_ml_database_migration(db, ML_METADATA_VERSION); - if (configure_sqlite_database(db, target_version)) { + if (configure_sqlite_database(db, target_version, "ml_config")) { error_report("Failed to setup ML database"); sqlite3_close(db); db = NULL; @@ -1805,13 +1809,17 @@ void ml_init() } } +uint64_t sqlite_get_ml_space(void) +{ + return sqlite_get_db_space(db); +} + void ml_fini() { - if (!Cfg.enable_anomaly_detection) + if (!Cfg.enable_anomaly_detection || !db) return; - int rc = sqlite3_close_v2(db); - if (unlikely(rc != SQLITE_OK)) - error_report("Error %d while closing the SQLite database, %s", rc, sqlite3_errstr(rc)); + sql_close_database(db, "ML"); + db = NULL; } void ml_start_threads() { @@ -1845,8 +1853,8 @@ void ml_stop_threads() if (!Cfg.detection_thread) return; - netdata_thread_cancel(Cfg.detection_thread); netdata_thread_join(Cfg.detection_thread, NULL); + Cfg.detection_thread = 0; // signal the training queue of each thread for (size_t idx = 0; idx != Cfg.num_training_threads; idx++) { |