From 117a304f68e74c8c1fe9e8f108baadd6c4a99e46 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 29 Mar 2026 22:18:51 -0300 Subject: [PATCH] khatru: relay stats. --- khatru/relay.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/khatru/relay.go b/khatru/relay.go index e09226f..ab97ac8 100644 --- a/khatru/relay.go +++ b/khatru/relay.go @@ -190,3 +190,15 @@ func (rl *Relay) getBaseURL(r *http.Request) string { return proto + "://" + host + r.URL.Path } + +// Stats returns the current number of connected clients and open listeners. +func (rl *Relay) Stats() (clients, listeners int) { + rl.clientsMutex.Lock() + defer rl.clientsMutex.Unlock() + + for _, specs := range rl.clients { + listeners += len(specs) + } + + return len(rl.clients), listeners +}