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/swarm/stats.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/swarm/stats.rs') diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index eb34276..ab5c4da 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -33,6 +33,17 @@ struct Inner { /// The document version (`AppState::change_tx`) and epoch the saved size is of. measured_version: Option<(u64, Epoch)>, propagation: Propagation, + disk: Disk, +} + +/// Files this node reads and writes for itself: the state file, a backup to recover +/// from. Not the Mycelium daemon's, and not logs. +#[derive(Debug, Clone, Copy, Default)] +pub(crate) struct Disk { + pub(crate) reads: u64, + pub(crate) read_bytes: u64, + pub(crate) writes: u64, + pub(crate) written_bytes: u64, } /// Upper bounds (inclusive, milliseconds) of the propagation delay buckets; a last @@ -107,6 +118,7 @@ pub(crate) struct Snapshot { pub(crate) max_heads: usize, pub(crate) stale_hello_replies: u64, pub(crate) propagation: Propagation, + pub(crate) disk: Disk, } impl Default for NodeStats { @@ -151,6 +163,20 @@ impl NodeStats { } } + /// A file of `bytes` was read (`Disk`). + pub(crate) fn disk_read(&self, bytes: u64) { + let mut inner = self.lock(); + inner.disk.reads += 1; + inner.disk.read_bytes += bytes; + } + + /// A file of `bytes` was written (`Disk`). + pub(crate) fn disk_written(&self, bytes: u64) { + let mut inner = self.lock(); + inner.disk.writes += 1; + inner.disk.written_bytes += bytes; + } + pub(crate) fn stale_hello_reply(&self) { self.lock().stale_hello_replies += 1; } @@ -205,6 +231,7 @@ impl NodeStats { max_heads: inner.max_heads, stale_hello_replies: inner.stale_hello_replies, propagation: inner.propagation, + disk: inner.disk, } } } -- cgit v1.3.1