Documentation
¶
Overview ¶
Package stats 通过 Xray gRPC StatsService 采集用户流量,并支持 HandlerService 动态更新用户。 实现模型对照《xray-api-探索.md》§4(3x-ui GetTraffic 轮询模式): QueryStats 全量拉取 → 维护 last 基线 → 差值 = 本周期增量(xray 重启归零视为 0)。
Index ¶
- type Collector
- func (c *Collector) Close()
- func (c *Collector) Collect(ctx context.Context) ([]Entry, error)
- func (c *Collector) OnlineSnapshot() []OnlineUser
- func (c *Collector) OnlineUsers() int
- func (c *Collector) ResetUsers()
- func (c *Collector) SyncUsers(ctx context.Context, targetUsers map[string][]protocol.User) error
- type Entry
- type OnlineUser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector 采集 Xray stats 并通过 HandlerService 动态同步用户。
func (*Collector) Collect ¶
Collect 拉取全量计数器并返回自上次以来的流量增量(用户维度 + 入站维度两个计数器族)。 若 xray 未运行/连接失败返回 error,由调用方决定重连。
func (*Collector) OnlineSnapshot ¶
func (c *Collector) OnlineSnapshot() []OnlineUser
OnlineSnapshot 返回最近一次 Collect 的在线用户 IP 快照(拷贝;未采集过则 nil)。
func (*Collector) OnlineUsers ¶
OnlineUsers 返回最近一次 Collect 观测到的在线用户数(未采集过则 0)。
func (*Collector) ResetUsers ¶
func (c *Collector) ResetUsers()
ResetUsers 重置内存中的用户缓存(在 Xray 重启后使用)。 旧进程的连接随重启全部消失,在线快照一并清零,避免心跳沿用旧进程的残影。
type OnlineUser ¶
OnlineUser 单个用户的在线快照:当前活跃连接的去重源 IP 列表。
Click to show internal directories.
Click to hide internal directories.