resource_tracker/metrics/disk.rs
1use crate::metrics::{DiskMountMetrics, DiskType};
2use serde::{Deserialize, Serialize};
3
4/// Per-device disk metrics: static identity (cached once) + dynamic throughput
5/// and filesystem space (polled each interval).
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct DiskMetrics {
8 // ------------------------------------------------------------------
9 // Identity - read from /sys/block/<dev>/ once at startup.
10 // ------------------------------------------------------------------
11 pub device: String,
12 /// e.g. "Samsung SSD 870 EVO 1TB", from `/sys/block/<dev>/device/model`.
13 pub model: Option<String>,
14 /// e.g. "ATA", from `/sys/block/<dev>/device/vendor`.
15 pub vendor: Option<String>,
16 /// World-Wide ID or serial, from `/sys/block/<dev>/device/wwid` or `serial`.
17 pub serial: Option<String>,
18 pub device_type: Option<DiskType>,
19 /// Total raw device capacity in bytes (`/sys/block/<dev>/size` × 512).
20 pub capacity_bytes: Option<u64>,
21
22 // ------------------------------------------------------------------
23 // Filesystem space - updated each poll via statvfs(3).
24 // One entry per mount point that belongs to this device.
25 // ------------------------------------------------------------------
26 pub mounts: Vec<DiskMountMetrics>,
27
28 // ------------------------------------------------------------------
29 // Throughput - derived from /proc/diskstats sector deltas.
30 // ------------------------------------------------------------------
31 pub read_bytes_per_sec: f64,
32 pub write_bytes_per_sec: f64,
33 /// Cumulative bytes read since boot (raw /proc/diskstats sector count × 512).
34 /// Matches Python resource-tracker's `disk_read_bytes` column.
35 pub read_bytes_total: u64,
36 /// Cumulative bytes written since boot (raw /proc/diskstats sector count × 512).
37 /// Matches Python resource-tracker's `disk_write_bytes` column.
38 pub write_bytes_total: u64,
39}