mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-22 04:48:06 +00:00
cleanup: add getter functions to stats_manager
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
This commit is contained in:
parent
b7adcd251d
commit
0195dba889
@ -63,6 +63,24 @@ public:
|
|||||||
const indexed_vector<falco_rule>& rules,
|
const indexed_vector<falco_rule>& rules,
|
||||||
std::string& out) const;
|
std::string& out) const;
|
||||||
|
|
||||||
|
// Getter functions
|
||||||
|
inline const std::atomic<uint64_t>& get_total() const
|
||||||
|
{
|
||||||
|
return m_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const std::vector<std::unique_ptr<std::atomic<uint64_t>>>& get_by_priority() const
|
||||||
|
{
|
||||||
|
return m_by_priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const std::vector<std::unique_ptr<std::atomic<uint64_t>>>& get_by_rule_id() const
|
||||||
|
{
|
||||||
|
return m_by_rule_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
std::atomic<uint64_t> m_total;
|
std::atomic<uint64_t> m_total;
|
||||||
std::vector<std::unique_ptr<std::atomic<uint64_t>>> m_by_priority;
|
std::vector<std::unique_ptr<std::atomic<uint64_t>>> m_by_priority;
|
||||||
std::vector<std::unique_ptr<std::atomic<uint64_t>>> m_by_rule_id;
|
std::vector<std::unique_ptr<std::atomic<uint64_t>>> m_by_rule_id;
|
||||||
|
@ -107,7 +107,6 @@ std::string falco_metrics::to_text(const falco::app::state& state)
|
|||||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus("evt_source", "falcosecurity", "falco", {{"evt_source", source}});
|
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus("evt_source", "falcosecurity", "falco", {{"evt_source", source}});
|
||||||
}
|
}
|
||||||
std::vector<metrics_v2> falco_metrics;
|
std::vector<metrics_v2> falco_metrics;
|
||||||
|
|
||||||
if(state.config->m_metrics_flags & METRICS_V2_RULE_COUNTERS)
|
if(state.config->m_metrics_flags & METRICS_V2_RULE_COUNTERS)
|
||||||
{
|
{
|
||||||
const stats_manager& rule_stats_manager = state.engine->get_rule_stats_manager();
|
const stats_manager& rule_stats_manager = state.engine->get_rule_stats_manager();
|
||||||
@ -117,9 +116,9 @@ std::string falco_metrics::to_text(const falco::app::state& state)
|
|||||||
METRIC_VALUE_TYPE_U64,
|
METRIC_VALUE_TYPE_U64,
|
||||||
METRIC_VALUE_UNIT_COUNT,
|
METRIC_VALUE_UNIT_COUNT,
|
||||||
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
|
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
|
||||||
rule_stats_manager.m_total.load()));
|
rule_stats_manager.get_total().load()));
|
||||||
|
|
||||||
for (size_t i = 0; i < rule_stats_manager.m_by_rule_id.size(); i++)
|
for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++)
|
||||||
{
|
{
|
||||||
auto rule = rules.at(i);
|
auto rule = rules.at(i);
|
||||||
std::string rules_metric_name = "rules." + rule->name;
|
std::string rules_metric_name = "rules." + rule->name;
|
||||||
@ -129,7 +128,7 @@ std::string falco_metrics::to_text(const falco::app::state& state)
|
|||||||
METRIC_VALUE_TYPE_U64,
|
METRIC_VALUE_TYPE_U64,
|
||||||
METRIC_VALUE_UNIT_COUNT,
|
METRIC_VALUE_UNIT_COUNT,
|
||||||
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
|
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
|
||||||
rule_stats_manager.m_by_rule_id[i]->load());
|
rule_stats_manager.get_by_rule_id()[i]->load());
|
||||||
prometheus_metrics_converter.convert_metric_to_unit_convention(metric);
|
prometheus_metrics_converter.convert_metric_to_unit_convention(metric);
|
||||||
const std::map<std::string, std::string>& const_labels = {
|
const std::map<std::string, std::string>& const_labels = {
|
||||||
{"priority", std::to_string(rule->priority)},
|
{"priority", std::to_string(rule->priority)},
|
||||||
|
@ -377,10 +377,10 @@ void stats_writer::collector::get_metrics_output_fields_additional(
|
|||||||
{
|
{
|
||||||
const stats_manager& rule_stats_manager = m_writer->m_engine->get_rule_stats_manager();
|
const stats_manager& rule_stats_manager = m_writer->m_engine->get_rule_stats_manager();
|
||||||
const indexed_vector<falco_rule>& rules = m_writer->m_engine->get_rules();
|
const indexed_vector<falco_rule>& rules = m_writer->m_engine->get_rules();
|
||||||
output_fields["falco.rules.matches_total"] = rule_stats_manager.m_total.load();
|
output_fields["falco.rules.matches_total"] = rule_stats_manager.get_total().load();
|
||||||
for (size_t i = 0; i < rule_stats_manager.m_by_rule_id.size(); i++)
|
for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++)
|
||||||
{
|
{
|
||||||
auto rule_count = rule_stats_manager.m_by_rule_id[i]->load();
|
auto rule_count = rule_stats_manager.get_by_rule_id()[i]->load();
|
||||||
if (rule_count == 0 && !m_writer->m_config->m_metrics_include_empty_values)
|
if (rule_count == 0 && !m_writer->m_config->m_metrics_include_empty_values)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user