Skip to content

API & Commands: Add GetUsersStatsRequest(); Improve api statsonlineiplist - #5776

Merged
RPRX merged 1 commit into
XTLS:mainfrom
kastov:feat/get-all-users-online-info
Apr 11, 2026
Merged

RPRX merged 1 commit into
XTLS:mainfrom
kastov:feat/get-all-users-online-info

Conversation

@kastov

@kastov kastov commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

Added methods to gRPC API and CLI command

Usage

./xray api statsonlineiplist --server=127.0.0.1:777 -all -include-traffic
{
    "users": [
        {
            "email": "[email protected]",
            "ips": [
                {
                    "ip": "1.2.3.4",
                    "lastSeen": 1775431553
                },
                {
                    "ip": "4.3.2.1",
                    "lastSeen": 1775431610
                }
            ],
            "traffic": {
                "downlink": 33495,
                "uplink": 70098
            }
        }
    ]
}
./xray api statsonlineiplist --server=127.0.0.1:777 -all
{
    "users": [
        {
            "email": "[email protected]",
            "ips": [
                {
                    "ip": "1.2.3.4",
                    "lastSeen": 1775431553
                },
                {
                    "ip": "4.3.2.1",
                    "lastSeen": 1775431610
                }
            ]
    ]
}

gRPC API:

GetUsersStatsRequest {
    $type: "xray.app.stats.command.GetUsersStatsRequest";
    includeTraffic: boolean;
    reset: boolean;
}

@kastov
kastov force-pushed the feat/get-all-users-online-info branch from bff4086 to 8751821 Compare March 8, 2026 14:02
@Fangliding

Copy link
Copy Markdown
Member

为什么不给 cmdOnlineStatsIpList 加一个 -all 的选项?

@kastov

kastov commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@Fangliding done

@Fangliding

Copy link
Copy Markdown
Member

。。。

@Fangliding Fangliding closed this Mar 9, 2026
@kastov

kastov commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@Fangliding why?

@kastov

kastov commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

i removed new CLI method and extended existing (d963245) as you asked...

@Fangliding

Fangliding commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

本来有一个用email query的选项 复用一下加个逻辑query全部不就行了 基础设施全在这里 结果你只是wrap了一下入口点 看起来你并没有考虑过内部的安排只是为了自己面板的需求让AI往核心堆垃圾然后打开PR

@Fangliding

Fangliding commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

至于别的 你们已经有了webhook 我没有很反对它的原因是因为它的的确确是一个非常强大的功能 你们完全可以通过它在自己的软件里构建一个更为完善的在线系统(你们甚至可以追踪具体的访问时间 访问网站次数和频率) 而不是在core再添加一套API

@kastov

kastov commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

if you meant to modify grpc method GetStatsOnlineIpList – changing it response type to array and make email optional – it will create breaking changes

@RPRX

RPRX commented Mar 30, 2026

Copy link
Copy Markdown
Member

赞助的力量

话说这个和现有 Online Map API 的区别在于?如果要 break 也不是不行反正都坏掉那么久了

@RPRX RPRX reopened this Mar 30, 2026
@kastov

kastov commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

The existing Online Map API doesn't have a way to get all users with their IPs in a single call. Right now you need N+1: GetAllOnlineUsers (emails only, no IPs) → then GetStatsOnlineIpList per user.

GetAllUsersOnlineInfo returns everything in one request — users, IPs, last seen timestamps.

The OnlineMap interface refactor (List()/IPTimeMap() → ForEach(), time.Time → int64) was done because I was targeting high-performance scenarios with frequent polling of this endpoint — the old methods allocated on every call and time.Time doesn't map to protobuf cleanly. But if this is too invasive, I can keep the existing interface untouched and implement GetAllUsersOnlineInfo on top of the current IPTimeMap() — it'll just be less efficient.

@TaiFil

TaiFil commented Mar 30, 2026 •

Copy link
Copy Markdown

It would be nice if there were a single complete query with ips, downlink, uplink:

./xray api statsonlinelist --server=127.0.0.1:777 --all
{
    "users": [
        {
            "email": "[email protected]",
            "ips": [
                {
                    "ip": "3.3.3.3",
                    "lastSeen": 1772922476
                }
            ],
            "uplink": 123,
            "downlink": 123
        }
    ]
}

@RPRX

RPRX commented Mar 31, 2026

Copy link
Copy Markdown
Member

实现上面这个 #5776 (comment) 来获取所有相关信息吧,加参数决定要不要仅 online 的、要不要流量统计,后续可继续扩展

@RPRX

RPRX commented Apr 5, 2026

Copy link
Copy Markdown
Member

#5776 (comment) 有进展吗

@kastov

This comment was marked as resolved.

@kastov
kastov force-pushed the feat/get-all-users-online-info branch from d963245 to afd39c2 Compare April 5, 2026 23:26
@kastov

kastov commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

@RPRX done. PR description was updated with examples.

@RPRX

RPRX commented Apr 11, 2026

Copy link
Copy Markdown
Member

对这些代码不熟,简单看了下 app/dispatcher/default.go,应该不会 panic

其它代码看起来是给 API 加了个 GetUsersStatsRequest() 而没有 breaking,给 command api statsonlineiplist 加了些参数

那就先这样吧,这些东西在出官方客户端后再看要不要重构一下

@RPRX RPRX changed the title API: retrieve all online users with their IPs API & Commands: Add GetUsersStatsRequest(); Improve api statsonlineiplist Apr 11, 2026
@RPRX

RPRX commented Apr 11, 2026

Copy link
Copy Markdown
Member

虽然 #5776 (comment) 我的意思是还支持“要不要仅 online 的”,变成一个完全通用接口,不过先这样吧,以后再加参数也行

@RPRX
RPRX merged commit a91a88c into XTLS:main Apr 11, 2026
39 checks passed
Exclude0122 pushed a commit to Exclude0122/Xray-core that referenced this pull request Apr 19, 2026
@kastov
kastov deleted the feat/get-all-users-online-info branch April 25, 2026 19:01
wyusgw pushed a commit to wyusgw/Xray-core that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants