From f52ae6973299fa3c1d81758838951e39904e1d84 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 13:38:59 +0100 Subject: add files module to consistently track stats --- src/api/stats/prometheus.rs | 53 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/api/stats') diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs index ea97bd2..e267042 100644 --- a/src/api/stats/prometheus.rs +++ b/src/api/stats/prometheus.rs @@ -297,31 +297,34 @@ 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, - ); + type Field = fn(&super::DiskStats) -> u64; + let disk: [(&str, &str, Field); 5] = [ + ("disk_reads_total", "Reads of this node's own files.", |c| { + c.reads + }), + ("disk_read_bytes_total", "Bytes read from them.", |c| { + c.read_bytes + }), + ( + "disk_writes_total", + "Writes of this node's own files.", + |c| c.writes, + ), + ("disk_written_bytes_total", "Bytes written to them.", |c| { + c.written_bytes + }), + ( + "disk_errors_total", + "Failed reads and writes of them.", + |c| c.errors, + ), + ]; + for (name, help, field) in disk { + out.family(name, "counter", help); + for (kind, counts) in &stats.disk { + out.sample(name, &[("file", *kind)], field(counts) as f64); + } + } let propagation = &stats.propagation; out.family( -- cgit v1.3.1