mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-03 10:18:42 +00:00
Expose online map in metrics
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user