diff options
| author | tv <tv@krebsco.de> | 2026-10-25 13:38:59 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-25 13:38:59 +0100 |
| commit | f52ae6973299fa3c1d81758838951e39904e1d84 (patch) | |
| tree | eeadc6f698d1fa99d33268f997e8def5ee403038 /src/api/stats.rs | |
| parent | 022ddb4bf167a12cd45b4a5cac27739f92449eff (diff) | |
add files module to consistently track stats
Diffstat (limited to 'src/api/stats.rs')
| -rw-r--r-- | src/api/stats.rs | 30 |
1 files changed, 21 insertions, 9 deletions
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(), } } |
