stats

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package stats 通过 Xray gRPC StatsService 采集用户流量,并支持 HandlerService 动态更新用户。 实现模型对照《xray-api-探索.md》§4(3x-ui GetTraffic 轮询模式): QueryStats 全量拉取 → 维护 last 基线 → 差值 = 本周期增量(xray 重启归零视为 0)。

Index

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 New

func New(apiAddr string) *Collector

New 构造采集器(apiAddr 如 127.0.0.1:10085)。

func (*Collector) Close

func (c *Collector) Close()

Close 关闭连接。

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context) ([]Entry, error)

Collect 拉取全量计数器并返回自上次以来的流量增量(用户维度 + 入站维度两个计数器族)。 若 xray 未运行/连接失败返回 error,由调用方决定重连。

func (*Collector) OnlineSnapshot

func (c *Collector) OnlineSnapshot() []OnlineUser

OnlineSnapshot 返回最近一次 Collect 的在线用户 IP 快照(拷贝;未采集过则 nil)。

func (*Collector) OnlineUsers

func (c *Collector) OnlineUsers() int

OnlineUsers 返回最近一次 Collect 观测到的在线用户数(未采集过则 0)。

func (*Collector) ResetUsers

func (c *Collector) ResetUsers()

ResetUsers 重置内存中的用户缓存(在 Xray 重启后使用)。 旧进程的连接随重启全部消失,在线快照一并清零,避免心跳沿用旧进程的残影。

func (*Collector) SyncUsers

func (c *Collector) SyncUsers(ctx context.Context, targetUsers map[string][]protocol.User) error

SyncUsers 通过 gRPC HandlerService 增量调整 Xray 中的用户。

type Entry

type Entry struct {
	Email   string
	Inbound string
	Up      int64
	Down    int64
}

Entry 单条流量增量(用户维度 Email / 入站维度 Inbound 二选一)。

type OnlineUser

type OnlineUser struct {
	Email string
	IPs   []string
}

OnlineUser 单个用户的在线快照:当前活跃连接的去重源 IP 列表。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL