diff --git a/userspace/falco/falco_metrics.cpp b/userspace/falco/falco_metrics.cpp index 0ef652ab0e3..883bdd8a48f 100644 --- a/userspace/falco/falco_metrics.cpp +++ b/userspace/falco/falco_metrics.cpp @@ -166,7 +166,8 @@ std::string falco_metrics::to_text(const falco::app::state& state) prometheus_metrics_converter.convert_metric_to_unit_convention(metric); prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric, "falcosecurity", "falco"); - for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++) + const std::vector>>& rules_by_id = rule_stats_manager.get_by_rule_id(); + for (size_t i = 0; i < rules_by_id.size(); i++) { auto rule = rules.at(i); std::string rules_metric_name = "rules." + rule->name; @@ -176,7 +177,7 @@ std::string falco_metrics::to_text(const falco::app::state& state) METRIC_VALUE_TYPE_U64, METRIC_VALUE_UNIT_COUNT, METRIC_VALUE_METRIC_TYPE_MONOTONIC, - rule_stats_manager.get_by_rule_id()[i]->load()); + rules_by_id[i]->load()); prometheus_metrics_converter.convert_metric_to_unit_convention(metric); const std::map& const_labels = { {"priority", std::to_string(rule->priority)}, diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index 0d70cdc7584..6c6f7cdca86 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -384,14 +384,16 @@ void stats_writer::collector::get_metrics_output_fields_additional( const stats_manager& rule_stats_manager = m_writer->m_engine->get_rule_stats_manager(); const indexed_vector& rules = m_writer->m_engine->get_rules(); output_fields["falco.rules.matches_total"] = rule_stats_manager.get_total().load(); - for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++) + const std::vector>>& rules_by_id = rule_stats_manager.get_by_rule_id(); + for (size_t i = 0; i < rules_by_id.size(); i++) { - auto rule_count = rule_stats_manager.get_by_rule_id()[i]->load(); + auto rule_count = rules_by_id[i]->load(); if (rule_count == 0 && !m_writer->m_config->m_metrics_include_empty_values) { continue; } - std::string rules_metric_name = "falco.rules." + rules.at(i)->name; + auto rule = rules.at(i); + std::string rules_metric_name = "falco.rules." + rule->name; output_fields[rules_metric_name] = rule_count; } }