Add a JSON-RPC stats endpoint for websites

Plain HTTP + JSON-RPC 2.0 (axum, already in the tree) so a site backend
can pull stats without gRPC stubs. Methods: stats.get (counters + gauges)
and stats.channel { channel } (lines + top talkers). Optional [jsonrpc]
config, off unless set.

Security: bearer-token authenticated with a constant-time compare, refuses
to start with an empty token, read-only (only stats.* methods — no way to
mutate state), method-allowlisted, a 64 KiB body limit, and meant to bind
to localhost beside the backend.
This commit is contained in:
Jean Chevronnet 2026-07-13 20:21:41 +00:00
parent 04f927d3db
commit 07eb9939d7
No known key found for this signature in database
6 changed files with 219 additions and 0 deletions

View file

@ -201,6 +201,11 @@ impl Engine {
self.network.bump(key);
}
// Per-channel activity (lines + top talkers) for the stats APIs.
pub fn channel_activity(&self, channel: &str) -> Option<(u64, Vec<(String, u64)>)> {
self.network.channel_activity(channel)
}
// The shared counters plus live gauges derived from the store, for the gRPC
// Stats API. Any service's counters ride in here alongside these.
pub fn stats_snapshot(&self) -> std::collections::BTreeMap<String, u64> {