Shared stats registry + gRPC Stats API

A single namespaced counter map on the engine that every service reports
into: ServiceCtx::count(key) is folded in after each command, the engine
bumps its own events (botserv.kick/ban/warn/greet/trigger), and a
per-service command counter (nickserv.command, chanserv.command, …) is
tallied in dispatch. stats_snapshot() merges those with live gauges from
the store (accounts/channels/bots/opers total).

Exposed over gRPC as a new Stats service (Get -> map<string,uint64>),
authorized by the same bearer token as Directory/Accounts — so any
consumer (a dashboard, Django) reads every module's stats through one
pipe. New service is additive to the proto; existing RPCs untouched.
This commit is contained in:
Jean Chevronnet 2026-07-13 19:13:31 +00:00
parent 5d1bfb3144
commit d4e2c905f2
No known key found for this signature in database
4 changed files with 111 additions and 8 deletions

View file

@ -168,6 +168,10 @@ pub struct Sender<'a> {
#[derive(Default)]
pub struct ServiceCtx {
pub actions: Vec<NetAction>,
// Namespaced stat counters to bump (e.g. "nickserv.register"). The engine
// folds these into the shared registry after the command runs — so every
// service reports its own stats through one shared pipe.
pub stats: Vec<String>,
}
impl ServiceCtx {
@ -179,6 +183,12 @@ impl ServiceCtx {
});
}
// Record a stat counter bump (namespaced, e.g. "chanserv.register"). Folded
// into the engine's shared registry, which the gRPC Stats API exposes.
pub fn count(&mut self, key: impl Into<String>) {
self.stats.push(key.into());
}
// A channel/target message sourced from one of our pseudo-clients (e.g. a
// bot answering a fantasy command, or BotServ SAY).
pub fn privmsg(&mut self, from: &str, to: &str, text: impl Into<String>) {