statserv: persist per-channel activity across restart too
All checks were successful
CI / check (push) Successful in 3m49s

The earlier StatsSet fix persisted only the shared namespaced counters. The
per-channel BOTSTATS view (lines seen + top talkers, from /statserv #chan) lived
on the LiveChannel struct, which is rebuilt from each burst — so it reset to zero
on restart. Move it to a name-keyed Network.chan_activity map (independent of live
membership, seedable before the burst) and carry it in the StatsSet snapshot
(new serde-default `channels` field) alongside the counters. Reworded the
notice from 'seen this session' now that it persists.
This commit is contained in:
Jean Chevronnet 2026-07-16 17:50:11 +00:00
parent 8a9b6a37ca
commit 1f6a11dba2
No known key found for this signature in database
8 changed files with 91 additions and 26 deletions

View file

@ -250,10 +250,24 @@ impl Db {
self.net.stats.clone()
}
/// Snapshot the live stat counters to the log so they survive a restart.
pub fn persist_stats(&mut self, counters: &std::collections::BTreeMap<String, u64>) -> std::io::Result<()> {
self.log.append(Event::StatsSet { counters: counters.iter().map(|(k, v)| (k.clone(), *v)).collect() })?;
/// The persisted per-channel activity, to seed BOTSTATS on startup.
pub fn persisted_chan_stats(&self) -> ChanStats {
self.net.chan_stats.clone()
}
/// Snapshot the live stats (shared counters + per-channel activity) to the log
/// so they survive a restart.
pub fn persist_stats(
&mut self,
counters: &std::collections::BTreeMap<String, u64>,
chan_stats: ChanStats,
) -> std::io::Result<()> {
self.log.append(Event::StatsSet {
counters: counters.iter().map(|(k, v)| (k.clone(), *v)).collect(),
channels: chan_stats.clone(),
})?;
self.net.stats = counters.clone();
self.net.chan_stats = chan_stats;
Ok(())
}