use crate::core::{MetricKey, MetricKind};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NetMetricKey {
PacketsReceived,
PacketsDropped,
BytesReceived,
BatchesPolled,
BatchSize,
RxRingOccupancy,
FillRingStarvation,
ParseFailures,
SinkWriteFailures,
}
impl NetMetricKey {
pub fn kind(self) -> MetricKind {
match self {
Self::RxRingOccupancy => MetricKind::Gauge,
Self::BatchSize => MetricKind::Histogram,
_ => MetricKind::Counter,
}
}
}
impl MetricKey for NetMetricKey {
fn name(&self) -> &str {
match self {
Self::PacketsReceived => "net.packets_received",
Self::PacketsDropped => "net.packets_dropped",
Self::BytesReceived => "net.bytes_received",
Self::BatchesPolled => "net.batches_polled",
Self::BatchSize => "net.batch_size",
Self::RxRingOccupancy => "net.rx_ring_occupancy",
Self::FillRingStarvation => "net.fill_ring_starvation",
Self::ParseFailures => "net.parse_failures",
Self::SinkWriteFailures => "net.sink_write_failures",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn kinds_and_names_cover_schema() {
let all = [
NetMetricKey::PacketsReceived,
NetMetricKey::PacketsDropped,
NetMetricKey::BytesReceived,
NetMetricKey::BatchesPolled,
NetMetricKey::BatchSize,
NetMetricKey::RxRingOccupancy,
NetMetricKey::FillRingStarvation,
NetMetricKey::ParseFailures,
NetMetricKey::SinkWriteFailures,
];
for key in all {
assert!(!key.name().is_empty());
assert!(key.name().starts_with("net."));
}
assert_eq!(NetMetricKey::BatchSize.kind(), MetricKind::Histogram);
assert_eq!(NetMetricKey::RxRingOccupancy.kind(), MetricKind::Gauge);
assert_eq!(NetMetricKey::PacketsReceived.kind(), MetricKind::Counter);
}
}