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.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/api/stats.rs') diff --git a/src/api/stats.rs b/src/api/stats.rs index 6c5e172..8899421 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -9,6 +9,8 @@ use axum::{ http::{HeaderMap, header}, response::{IntoResponse, Response}, }; +use std::collections::BTreeMap; + use serde::Serialize; use super::peers::EpochInfo; @@ -35,11 +37,11 @@ pub(crate) struct StatsResponse { /// The peers listed in /peers together (a forgotten peer's are gone). incidents: Incidents, propagation: PropagationStats, - disk: DiskStats, + /// This node's own files (`files`), by kind. + disk: BTreeMap<&'static str, DiskStats>, } -/// Files this node reads and writes for itself (the state file, a backup to recover -/// from), since it started. +/// Reads and writes of one kind of file, since the node started. #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct DiskStats { @@ -47,6 +49,7 @@ struct DiskStats { read_bytes: u64, writes: u64, written_bytes: u64, + errors: u64, } /// How long changes written elsewhere took from their commit there until applied here, @@ -207,11 +210,20 @@ 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, - }, + disk: state + .files + .counts() + .into_iter() + .map(|(kind, counts)| { + let stats = DiskStats { + reads: counts.reads, + read_bytes: counts.read_bytes, + writes: counts.writes, + written_bytes: counts.written_bytes, + errors: counts.errors, + }; + (kind.as_str(), stats) + }) + .collect(), } } -- cgit v1.3.1