From 8562dcb19ffbe36d1650017e3cc701d90a79631b Mon Sep 17 00:00:00 2001 From: Fangliding Date: Sat, 6 Jun 2026 06:13:01 +0800 Subject: [PATCH] Expose online map in metrics --- app/metrics/metrics.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/metrics/metrics.go b/app/metrics/metrics.go index a2ae2f30c..ed037d1a6 100644 --- a/app/metrics/metrics.go +++ b/app/metrics/metrics.go @@ -57,6 +57,26 @@ func NewMetricsHandler(ctx context.Context, config *Config) (*MetricsHandler, er }) return resp })) + expvar.Publish("online", expvar.Func(func() interface{} { + resp := map[string]interface{}{} + c.statsManager.VisitOnlineMaps(func(name string, om feature_stats.OnlineMap) bool { + user := name + if parts := strings.Split(name, ">>>"); len(parts) >= 2 { + user = parts[1] + } + ips := map[string]int64{} + om.ForEach(func(ip string, lastSeen int64) bool { + ips[ip] = lastSeen + return true + }) + resp[user] = map[string]interface{}{ + "count": om.Count(), + "ips": ips, + } + return true + }) + return resp + })) expvar.Publish("observatory", expvar.Func(func() interface{} { if c.observatory == nil { common.Must(core.RequireFeatures(ctx, func(observatory extension.Observatory) error {