Skip to content

Commit 0ac4a2a

Browse files
committed
expose num_evts metric in Prometheus output (#3584)
The `num_evts` counter is already emitted by the JSON / text stats sinks (via stats_writer::collector::get_metrics_output_fields_wrapper) but the Prometheus output sink at /metrics never got it. Anyone running Falco with prometheus_metrics_enabled couldn't see how many events the agent had processed. Three small wires to bridge the gap: app/state.h add `std::atomic<uint64_t> num_evts = 0;` to the shared state so a counter is reachable from both the per-source event loop and the prometheus sink without plumbing stats_writer through. app/actions/process_events.cpp after each `num_evts++` for the local source counter, also bump `s.num_evts` with relaxed memory ordering. Cheap, lock-free counter increment per event. falco_metrics.cpp emit a `falcosecurity_falco_num_evts_total` counter alongside the existing `falcosecurity_falco_outputs_queue_num_drops_total` block in `falco_to_text_prometheus`. Same metric type / unit pattern as the queue-drops counter just above it. Output: # HELP falcosecurity_falco_num_evts_total https://falco.org/docs/metrics/ # TYPE falcosecurity_falco_num_evts_total counter falcosecurity_falco_num_evts_total 12345
1 parent af5bd6c commit 0ac4a2a

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

userspace/falco/app/actions/process_events.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ static falco::app::run_result do_inspect(
386386
}
387387

388388
num_evts++;
389+
// Mirror the per-source counter into the shared state so the
390+
// Prometheus output sink can publish a global `num_evts` metric
391+
// alongside the JSON / text sinks. See issue #3584.
392+
s.num_evts.fetch_add(1, std::memory_order_relaxed);
389393
}
390394

391395
return run_result::ok();

userspace/falco/app/state.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ struct state {
7474
falco::app::options options;
7575
std::atomic<bool> restart = false;
7676

77+
// Cumulative count of userspace events processed by Falco across every
78+
// loaded event source. Maintained by the per-source event loop in
79+
// process_events.cpp and read by the Prometheus output sink so the
80+
// `falco.num_evts` value already exposed via stats_writer is also
81+
// available on /metrics. See issue #3584.
82+
std::atomic<uint64_t> num_evts = 0;
83+
7784
std::shared_ptr<falco_configuration> config;
7885
std::shared_ptr<falco_outputs> outputs;
7986
std::shared_ptr<falco_engine> engine;

userspace/falco/falco_metrics.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ std::string falco_metrics::falco_to_text_prometheus(
162162
state.outputs->get_outputs_queue_num_drops()));
163163
}
164164

165+
// # HELP falcosecurity_falco_num_evts_total https://falco.org/docs/metrics/
166+
// # TYPE falcosecurity_falco_num_evts_total counter
167+
// falcosecurity_falco_num_evts_total 12345
168+
//
169+
// Exposes the same `num_evts` counter that the JSON / text stats sinks
170+
// already emit via stats_writer; aggregated across every event source.
171+
// See issue #3584.
172+
additional_wrapper_metrics.emplace_back(libs::metrics::libsinsp_metrics::new_metric(
173+
"num_evts",
174+
METRICS_V2_MISC,
175+
METRIC_VALUE_TYPE_U64,
176+
METRIC_VALUE_UNIT_COUNT,
177+
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
178+
state.num_evts.load(std::memory_order_relaxed)));
179+
165180
// # HELP falcosecurity_falco_reload_timestamp_nanoseconds https://falco.org/docs/metrics/
166181
// # TYPE falcosecurity_falco_reload_timestamp_nanoseconds gauge
167182
// falcosecurity_falco_reload_timestamp_nanoseconds 1748338536592811359

0 commit comments

Comments
 (0)