diff options
author | vkalintiris <vasilis@netdata.cloud> | 2023-03-21 18:31:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 18:31:56 +0200 |
commit | 5321ca8d1ef8d974a6a2b2128ca8804de6acb693 (patch) | |
tree | 05846664d6fdb9ba33845e9081a90dc5d7e60e26 /ml/ad_charts.cc | |
parent | cbdf236f0e62655a468fe07e2f3c00037bff327c (diff) |
Revert "Use static thread-pool for training. (#14702)" (#14782)
This reverts commit 5046e034212c008557dd014196b6f6204eda24b2.
Will re-apply once we investigate an issue that occurs during
the shutdown of the agent.
Diffstat (limited to 'ml/ad_charts.cc')
-rw-r--r-- | ml/ad_charts.cc | 167 |
1 files changed, 69 insertions, 98 deletions
diff --git a/ml/ad_charts.cc b/ml/ad_charts.cc index 086cd5aa02..a32ff6c650 100644 --- a/ml/ad_charts.cc +++ b/ml/ad_charts.cc @@ -6,7 +6,7 @@ void ml_update_dimensions_chart(ml_host_t *host, const ml_machine_learning_stats /* * Machine learning status */ - if (Cfg.enable_statistics_charts) { + { if (!host->machine_learning_status_rs) { char id_buf[1024]; char name_buf[1024]; @@ -48,7 +48,7 @@ void ml_update_dimensions_chart(ml_host_t *host, const ml_machine_learning_stats /* * Metric type */ - if (Cfg.enable_statistics_charts) { + { if (!host->metric_type_rs) { char id_buf[1024]; char name_buf[1024]; @@ -90,7 +90,7 @@ void ml_update_dimensions_chart(ml_host_t *host, const ml_machine_learning_stats /* * Training status */ - if (Cfg.enable_statistics_charts) { + { if (!host->training_status_rs) { char id_buf[1024]; char name_buf[1024]; @@ -179,6 +179,7 @@ void ml_update_dimensions_chart(ml_host_t *host, const ml_machine_learning_stats rrdset_done(host->dimensions_rs); } + } void ml_update_host_and_detection_rate_charts(ml_host_t *host, collected_number AnomalyRate) { @@ -300,20 +301,20 @@ void ml_update_host_and_detection_rate_charts(ml_host_t *host, collected_number } } -void ml_update_training_statistics_chart(ml_training_thread_t *training_thread, const ml_training_stats_t &ts) { +void ml_update_training_statistics_chart(ml_host_t *host, const ml_training_stats_t &ts) { /* * queue stats */ { - if (!training_thread->queue_stats_rs) { + if (!host->queue_stats_rs) { char id_buf[1024]; char name_buf[1024]; - snprintfz(id_buf, 1024, "training_queue_%zu_stats", training_thread->id); - snprintfz(name_buf, 1024, "training_queue_%zu_stats", training_thread->id); + snprintfz(id_buf, 1024, "queue_stats_on_%s", localhost->machine_guid); + snprintfz(name_buf, 1024, "queue_stats_on_%s", rrdhost_hostname(localhost)); - training_thread->queue_stats_rs = rrdset_create( - localhost, + host->queue_stats_rs = rrdset_create( + host->rh, "netdata", // type id_buf, // id name_buf, // name @@ -327,35 +328,35 @@ void ml_update_training_statistics_chart(ml_training_thread_t *training_thread, localhost->rrd_update_every, // update_every RRDSET_TYPE_LINE// chart_type ); - rrdset_flag_set(training_thread->queue_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION); + rrdset_flag_set(host->queue_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION); - training_thread->queue_stats_queue_size_rd = - rrddim_add(training_thread->queue_stats_rs, "queue_size", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); - training_thread->queue_stats_popped_items_rd = - rrddim_add(training_thread->queue_stats_rs, "popped_items", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->queue_stats_queue_size_rd = + rrddim_add(host->queue_stats_rs, "queue_size", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->queue_stats_popped_items_rd = + rrddim_add(host->queue_stats_rs, "popped_items", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } - rrddim_set_by_pointer(training_thread->queue_stats_rs, - training_thread->queue_stats_queue_size_rd, ts.queue_size); - rrddim_set_by_pointer(training_thread->queue_stats_rs, - training_thread->queue_stats_popped_items_rd, ts.num_popped_items); + rrddim_set_by_pointer(host->queue_stats_rs, + host->queue_stats_queue_size_rd, ts.queue_size); + rrddim_set_by_pointer(host->queue_stats_rs, + host->queue_stats_popped_items_rd, ts.num_popped_items); - rrdset_done(training_thread->queue_stats_rs); + rrdset_done(host->queue_stats_rs); } /* * training stats */ { - if (!training_thread->training_time_stats_rs) { + if (!host->training_time_stats_rs) { char id_buf[1024]; char name_buf[1024]; - snprintfz(id_buf, 1024, "training_queue_%zu_time_stats", training_thread->id); - snprintfz(name_buf, 1024, "training_queue_%zu_time_stats", training_thread->id); + snprintfz(id_buf, 1024, "training_time_stats_on_%s", localhost->machine_guid); + snprintfz(name_buf, 1024, "training_time_stats_on_%s", rrdhost_hostname(localhost)); - training_thread->training_time_stats_rs = rrdset_create( - localhost, + host->training_time_stats_rs = rrdset_create( + host->rh, "netdata", // type id_buf, // id name_buf, // name @@ -369,39 +370,39 @@ void ml_update_training_statistics_chart(ml_training_thread_t *training_thread, localhost->rrd_update_every, // update_every RRDSET_TYPE_LINE// chart_type ); - rrdset_flag_set(training_thread->training_time_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION); - - training_thread->training_time_stats_allotted_rd = - rrddim_add(training_thread->training_time_stats_rs, "allotted", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_time_stats_consumed_rd = - rrddim_add(training_thread->training_time_stats_rs, "consumed", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_time_stats_remaining_rd = - rrddim_add(training_thread->training_time_stats_rs, "remaining", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); + rrdset_flag_set(host->training_time_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION); + + host->training_time_stats_allotted_rd = + rrddim_add(host->training_time_stats_rs, "allotted", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); + host->training_time_stats_consumed_rd = + rrddim_add(host->training_time_stats_rs, "consumed", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); + host->training_time_stats_remaining_rd = + rrddim_add(host->training_time_stats_rs, "remaining", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); } - rrddim_set_by_pointer(training_thread->training_time_stats_rs, - training_thread->training_time_stats_allotted_rd, ts.allotted_ut); - rrddim_set_by_pointer(training_thread->training_time_stats_rs, - training_thread->training_time_stats_consumed_rd, ts.consumed_ut); - rrddim_set_by_pointer(training_thread->training_time_stats_rs, - training_thread->training_time_stats_remaining_rd, ts.remaining_ut); + rrddim_set_by_pointer(host->training_time_stats_rs, + host->training_time_stats_allotted_rd, ts.allotted_ut); + rrddim_set_by_pointer(host->training_time_stats_rs, + host->training_time_stats_consumed_rd, ts.consumed_ut); + rrddim_set_by_pointer(host->training_time_stats_rs, + host->training_time_stats_remaining_rd, ts.remaining_ut); - rrdset_done(training_thread->training_time_stats_rs); + rrdset_done(host->training_time_stats_rs); } /* * training result stats */ { - if (!training_thread->training_results_rs) { + if (!host->training_results_rs) { char id_buf[1024]; char name_buf[1024]; - snprintfz(id_buf, 1024, "training_queue_%zu_results", training_thread->id); - snprintfz(name_buf, 1024, "training_queue_%zu_results", training_thread->id); + snprintfz(id_buf, 1024, "training_results_on_%s", localhost->machine_guid); + snprintfz(name_buf, 1024, "training_results_on_%s", rrdhost_hostname(localhost)); - training_thread->training_results_rs = rrdset_create( - localhost, + host->training_results_rs = rrdset_create( + host->rh, "netdata", // type id_buf, // id name_buf, // name @@ -415,61 +416,31 @@ void ml_update_training_statistics_chart(ml_training_thread_t *training_thread, localhost->rrd_update_every, // update_every RRDSET_TYPE_LINE// chart_type ); - rrdset_flag_set(training_thread->training_results_rs, RRDSET_FLAG_ANOMALY_DETECTION); - - training_thread->training_results_ok_rd = - rrddim_add(training_thread->training_results_rs, "ok", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_results_invalid_query_time_range_rd = - rrddim_add(training_thread->training_results_rs, "invalid-queries", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_results_not_enough_collected_values_rd = - rrddim_add(training_thread->training_results_rs, "not-enough-values", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_results_null_acquired_dimension_rd = - rrddim_add(training_thread->training_results_rs, "null-acquired-dimensions", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); - training_thread->training_results_chart_under_replication_rd = - rrddim_add(training_thread->training_results_rs, "chart-under-replication", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + rrdset_flag_set(host->training_results_rs, RRDSET_FLAG_ANOMALY_DETECTION); + + host->training_results_ok_rd = + rrddim_add(host->training_results_rs, "ok", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->training_results_invalid_query_time_range_rd = + rrddim_add(host->training_results_rs, "invalid-queries", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->training_results_not_enough_collected_values_rd = + rrddim_add(host->training_results_rs, "not-enough-values", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->training_results_null_acquired_dimension_rd = + rrddim_add(host->training_results_rs, "null-acquired-dimensions", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + host->training_results_chart_under_replication_rd = + rrddim_add(host->training_results_rs, "chart-under-replication", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } - rrddim_set_by_pointer(training_thread->training_results_rs, - training_thread->training_results_ok_rd, ts.training_result_ok); - rrddim_set_by_pointer(training_thread->training_results_rs, - training_thread->training_results_invalid_query_time_range_rd, ts.training_result_invalid_query_time_range); - rrddim_set_by_pointer(training_thread->training_results_rs, - training_thread->training_results_not_enough_collected_values_rd, ts.training_result_not_enough_collected_values); - rrddim_set_by_pointer(training_thread->training_results_rs, - training_thread->training_results_null_acquired_dimension_rd, ts.training_result_null_acquired_dimension); - rrddim_set_by_pointer(training_thread->training_results_rs, - training_thread->training_results_chart_under_replication_rd, ts.training_result_chart_under_replication); - - rrdset_done(training_thread->training_results_rs); - } -} - -void ml_update_global_statistics_charts(uint64_t models_consulted) { - if (Cfg.enable_statistics_charts) { - static RRDSET *st = NULL; - static RRDDIM *rd = NULL; - - if (unlikely(!st)) { - st = rrdset_create_localhost( - "netdata" // type - , "ml_models_consulted" // id - , NULL // name - , NETDATA_ML_CHART_FAMILY // family - , NULL // context - , "KMeans models used for prediction" // title - , "models" // units - , NETDATA_ML_PLUGIN // plugin - , NETDATA_ML_MODULE_DETECTION // module - , NETDATA_ML_CHART_PRIO_MACHINE_LEARNING_STATUS // priority - , localhost->rrd_update_every // update_every - , RRDSET_TYPE_AREA // chart_type - ); - - rd = rrddim_add(st, "num_models_consulted", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); - } - - rrddim_set_by_pointer(st, rd, (collected_number) models_consulted); - - rrdset_done(st); + rrddim_set_by_pointer(host->training_results_rs, + host->training_results_ok_rd, ts.training_result_ok); + rrddim_set_by_pointer(host->training_results_rs, + host->training_results_invalid_query_time_range_rd, ts.training_result_invalid_query_time_range); + rrddim_set_by_pointer(host->training_results_rs, + host->training_results_not_enough_collected_values_rd, ts.training_result_not_enough_collected_values); + rrddim_set_by_pointer(host->training_results_rs, + host->training_results_null_acquired_dimension_rd, ts.training_result_null_acquired_dimension); + rrddim_set_by_pointer(host->training_results_rs, + host->training_results_chart_under_replication_rd, ts.training_result_chart_under_replication); + + rrdset_done(host->training_results_rs); } } |