use crate::stats::CaptureStats;
pub const COUNTER_PACKETS: &str = "netring_capture_packets_total";
pub const COUNTER_DROPS: &str = "netring_capture_drops_total";
pub const COUNTER_FREEZES: &str = "netring_capture_freezes_total";
pub fn record_capture_delta(iface: &str, delta: &CaptureStats) {
let iface_label = iface.to_string();
metrics::counter!(COUNTER_PACKETS, "iface" => iface_label.clone())
.increment(delta.packets as u64);
metrics::counter!(COUNTER_DROPS, "iface" => iface_label.clone()).increment(delta.drops as u64);
metrics::counter!(COUNTER_FREEZES, "iface" => iface_label).increment(delta.freeze_count as u64);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn counter_names_have_total_suffix() {
assert!(COUNTER_PACKETS.ends_with("_total"));
assert!(COUNTER_DROPS.ends_with("_total"));
assert!(COUNTER_FREEZES.ends_with("_total"));
}
#[test]
fn record_does_not_panic_with_no_recorder() {
let delta = CaptureStats {
packets: 1234,
drops: 5,
freeze_count: 0,
};
record_capture_delta("test_iface", &delta);
}
}