Compare commits

..
Author SHA1 Message Date
Fangliding 8562dcb19f Expose online map in metrics 2026-06-06 06:13:01 +08:00
2 changed files with 20 additions and 7 deletions
+20
View File
@@ -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 {
-7
View File
@@ -2,8 +2,6 @@ package tun
import (
"context"
"net/netip"
"strings"
"syscall"
"github.com/xtls/xray-core/common"
@@ -82,11 +80,6 @@ func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routin
return nil
}
return c.Control(func(fd uintptr) {
addrPort, _ := netip.ParseAddrPort(address)
// skip loopback
if addrPort.Addr().IsLoopback() || strings.HasPrefix(strings.ToLower(address), "localhost:") {
return
}
err := setinterface(network, address, fd, iface)
if err != nil {
errors.LogInfoInner(context.Background(), err, "[tun] falied to set interface")