From 8e187d48b3da4de542a6299b7fdfffbd9c8df537 Mon Sep 17 00:00:00 2001 From: Melissa Kilby Date: Sat, 18 Nov 2023 04:24:07 +0000 Subject: [PATCH] cleanup(userspace/falco): minor adjustments to stats writer Signed-off-by: Melissa Kilby --- userspace/falco/stats_writer.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index 2be9f1bab88..e932c346b1b 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -232,7 +232,7 @@ void stats_writer::worker() noexcept } catch(const std::exception &e) { - falco_logger::log(LOG_ERR, "stats_writer (worker): " + std::string(e.what()) + "\n"); + falco_logger::log(falco_logger::level::ERR, "stats_writer (worker): " + std::string(e.what()) + "\n"); } } } @@ -280,7 +280,7 @@ void stats_writer::collector::get_metrics_output_fields_wrapper( if (m_last_num_evts != 0 && stats_snapshot_time_delta_sec > 0) { /* Successfully processed userspace event rate. */ - output_fields["falco.evts_rate_sec"] = (double)((num_evts - m_last_num_evts) / (double)stats_snapshot_time_delta_sec); + output_fields["falco.evts_rate_sec"] = std::round((double)((num_evts - m_last_num_evts) / (double)stats_snapshot_time_delta_sec) * 10.0) / 10.0; // round to 1 decimal } output_fields["falco.num_evts"] = num_evts; output_fields["falco.num_evts_prev"] = m_last_num_evts; @@ -380,10 +380,9 @@ void stats_writer::collector::get_metrics_output_fields_additional( { flags &= ~PPM_SCAP_STATS_LIBBPF_STATS; } - if (!(machine_info->flags & PPM_BPF_STATS_ENABLED)) - { - flags &= ~PPM_SCAP_STATS_LIBBPF_STATS; - } + + // Note: ENGINE_FLAG_BPF_STATS_ENABLED check has been moved to libs, that is, when libbpf stats is not enabled + // in the kernel settings we won't collect them even if the end user enabled the libbpf stats option const scap_stats_v2* scap_stats_v2_snapshot = inspector->get_capture_stats_v2(flags, &nstats, &rc); if (scap_stats_v2_snapshot && nstats > 0 && rc == 0) @@ -416,7 +415,7 @@ void stats_writer::collector::get_metrics_output_fields_additional( if (n_evts_delta != 0 && stats_snapshot_time_delta_sec > 0) { /* n_evts is total number of kernel side events. */ - output_fields["scap.evts_rate_sec"] = (double)(n_evts_delta / stats_snapshot_time_delta_sec); + output_fields["scap.evts_rate_sec"] = std::round((double)(n_evts_delta / stats_snapshot_time_delta_sec) * 10.0) / 10.0; // round to 1 decimal } else { @@ -434,7 +433,7 @@ void stats_writer::collector::get_metrics_output_fields_additional( if (n_drops_delta != 0 && stats_snapshot_time_delta_sec > 0) { /* n_drops is total number of kernel side event drops. */ - output_fields["scap.evts_drop_rate_sec"] = (double)(n_drops_delta / stats_snapshot_time_delta_sec); + output_fields["scap.evts_drop_rate_sec"] = std::round((double)(n_drops_delta / stats_snapshot_time_delta_sec) * 10.0) / 10.0; // round to 1 decimal } else {