1use std::cell::Cell;
2
3#[cfg(feature = "prometheus")]
4mod prometheus;
5
6#[cfg(feature = "prometheus")]
7pub use prometheus::*;
8
9thread_local! {
10 pub(crate) static IGNORED_BY_PACKET_FILTER_PKT: Cell<u64> = const { Cell::new(0) };
11 pub(crate) static IGNORED_BY_PACKET_FILTER_BYTE: Cell<u64> = const { Cell::new(0) };
12 pub(crate) static DROPPED_MIDDLE_OF_CONNECTION_TCP_PKT: Cell<u64> = const { Cell::new(0) };
13 pub(crate) static DROPPED_MIDDLE_OF_CONNECTION_TCP_BYTE: Cell<u64> = const { Cell::new(0) };
14 pub(crate) static TOTAL_PKT: Cell<u64> = const { Cell::new(0) };
15 pub(crate) static TOTAL_BYTE: Cell<u64> = const { Cell::new(0) };
16 pub(crate) static TCP_PKT: Cell<u64> = const { Cell::new(0) };
17 pub(crate) static TCP_BYTE: Cell<u64> = const { Cell::new(0) };
18 pub(crate) static UDP_PKT: Cell<u64> = const { Cell::new(0) };
19 pub(crate) static UDP_BYTE: Cell<u64> = const { Cell::new(0) };
20 pub(crate) static TCP_NEW_CONNECTIONS: Cell<u64> = const { Cell::new(0) };
21 pub(crate) static UDP_NEW_CONNECTIONS: Cell<u64> = const { Cell::new(0) };
22 pub(crate) static IDLE_CYCLES: Cell<u64> = const { Cell::new(0) };
23 pub(crate) static TOTAL_CYCLES: Cell<u64> = const { Cell::new(0) };
24
25 #[cfg(feature = "prometheus")]
26 pub(crate) static PROMETHEUS: std::cell::OnceCell<prometheus::PerCorePrometheusStats> = const { std::cell::OnceCell::new() };
27}
28
29pub(crate) trait StatExt: Sized {
30 fn inc(&'static self) {
31 self.inc_by(1);
32 }
33 fn inc_by(&'static self, val: u64);
34}
35
36impl StatExt for std::thread::LocalKey<Cell<u64>> {
37 fn inc_by(&'static self, val: u64) {
38 self.set(self.get() + val);
39 }
40}