Skip to main content

resource_tracker/metrics/
network.rs

1use serde::{Deserialize, Serialize};
2
3/// Per-interface metrics: static identity (cached once) + dynamic throughput
4/// and link state (polled each interval).
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct NetworkMetrics {
7    // ------------------------------------------------------------------
8    // Identity - read from /sys/class/net/<iface>/ once at startup.
9    // ------------------------------------------------------------------
10    pub interface: String,
11    /// MAC address, e.g. "00:11:22:33:44:55".
12    pub mac_address: Option<String>,
13    /// Kernel driver name, e.g. "igc", "virtio_net".
14    pub driver: Option<String>,
15
16    // ------------------------------------------------------------------
17    // Link state - polled each interval (operstate can flap; speed can
18    // change on auto-negotiation).
19    // ------------------------------------------------------------------
20    /// "up", "down", "unknown", etc. from `/sys/class/net/<iface>/operstate`.
21    pub operstate: Option<String>,
22    /// Link speed in Mbps. -1 when the driver does not report it.
23    pub speed_mbps: Option<i64>,
24    /// MTU in bytes.
25    pub mtu: Option<u32>,
26
27    // ------------------------------------------------------------------
28    // Throughput - derived from /proc/net/dev byte deltas.
29    // ------------------------------------------------------------------
30    pub rx_bytes_per_sec: f64,
31    pub tx_bytes_per_sec: f64,
32    /// Cumulative bytes received since boot (raw /proc/net/dev counter).
33    /// Matches Python resource-tracker's `net_recv_bytes` column.
34    pub rx_bytes_total: u64,
35    /// Cumulative bytes sent since boot (raw /proc/net/dev counter).
36    /// Matches Python resource-tracker's `net_sent_bytes` column.
37    pub tx_bytes_total: u64,
38}