From 3af7c116d41c06822006fb447211e3792862fd7c Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 13:07:48 +0100 Subject: add disk I/O stats --- src/api/stats.rs | 18 ++++++++++++++++++ src/api/stats/prometheus.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'src/api') diff --git a/src/api/stats.rs b/src/api/stats.rs index 838cc0f..6c5e172 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -35,6 +35,18 @@ pub(crate) struct StatsResponse { /// The peers listed in /peers together (a forgotten peer's are gone). incidents: Incidents, propagation: PropagationStats, + disk: DiskStats, +} + +/// Files this node reads and writes for itself (the state file, a backup to recover +/// from), since it started. +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct DiskStats { + reads: u64, + read_bytes: u64, + writes: u64, + written_bytes: u64, } /// How long changes written elsewhere took from their commit there until applied here, @@ -195,5 +207,11 @@ async fn collect(state: &AppState) -> StatsResponse { .map(|(le_ms, count)| PropagationBucket { le_ms, count }) .collect(), }, + disk: DiskStats { + reads: node.disk.reads, + read_bytes: node.disk.read_bytes, + writes: node.disk.writes, + written_bytes: node.disk.written_bytes, + }, } } diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs index f68ca85..ea97bd2 100644 --- a/src/api/stats/prometheus.rs +++ b/src/api/stats/prometheus.rs @@ -297,6 +297,32 @@ pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String { stats.stale_hello_replies as f64, ); + let disk = &stats.disk; + out.single( + "disk_reads_total", + "counter", + "Files this node read for itself (state file, backup).", + disk.reads as f64, + ); + out.single( + "disk_read_bytes_total", + "counter", + "Bytes of those files.", + disk.read_bytes as f64, + ); + out.single( + "disk_writes_total", + "counter", + "Files this node wrote for itself (state file).", + disk.writes as f64, + ); + out.single( + "disk_written_bytes_total", + "counter", + "Bytes of those files.", + disk.written_bytes as f64, + ); + let propagation = &stats.propagation; out.family( "propagation_delay_seconds", -- cgit v1.3.1