Xray-core
Xray-core copied to clipboard
API: Add user online stats
implement custom counter for ips connected to each client by email
- add statsUserOnline to config.json add statsUserOnline bool to policy
"levels": {
"0": {
"statsUserDownlink": true,
"statsUserUplink": true,
** "statsUserOnline": true
},
- each ip will remain in list for 20 sec (may we can add custom value to config) https://github.com/XTLS/Xray-core/commit/0b8ad84c2ba213f79d2552de896da8b79d68fa3c
- client should have an email.
- get user online from api :
./xray api statsonline -server=127.0.0.1:8080 -email "[email protected]"
{
"stat": {
"name": "user>>>[email protected]>>>online",
"value": "3"
}
}
this implementation based on https://github.com/XTLS/Xray-core/pull/2277#issuecomment-2254770107 discussion and may needs some review to improve and suggestions. @mmmray @yuhan6665
hello @amir-devman please review if this API is sufficient for your usecase as well. the implementation looks fine to me at a glance, as it is disabled by default performance doesn't seem critical.
each ip will remain in list for 20 sec (may we can add custom value to config)
That is a good option You can also add option to NOT mark a user as Online, if it's not connected for more than N seconds (if user just did a Real-Delay test, it's not online)
Looks good to me! Thanks for the effort to move to API solution. I will close #2277 for now
each ip will remain in list for 20 sec (may we can add custom value to config)
That is a good option You can also add option to NOT mark a user as Online, if it's not connected for more than N seconds (if user just did a Real-Delay test, it's not online)
that's a good idea, checking what i can do.
https://github.com/XTLS/Xray-core/pull/3644#issuecomment-2272712048
Cannot Checking Number User Online Stats While Using Xray Fallback Xtls Vision 443
=== When using the Xray API to check online user stats, the command xray api statsonline -server=127.0.0.1:10087 -email "segs" is returning the following output:
{ "stat": { "name": "user>>>segs>>>online" } }
The output indicates that the user is online but does not show the expected value for the number ip login.
@hossinasaadi Can you help to resolve conflict? I think it is time to merge
is it possible to get all users online stats with single request ?
@hossinasaadi
在某些场景下,使用示例中的基础配置时,会周期性地出现以下结果:
panic: runtime error:
invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x406396]
goroutine 1206045 [running]:
github.com/xtls/xray-core/app/stats.(*OnlineMap).AddIP(0xc002690000, {0xc000669980, 0xd})
github.com/xtls/xray-core/app/stats/online_map.go:43 +0x65
github.com/xtls/xray-core/app/dispatcher.(*DefaultDispatcher).getLink(0xc0017ea360, {0x1563828, 0xc0084a8d80})
github.com/xtls/xray-core/app/dispatcher/default.go:190 +0x53f
github.com/xtls/xray-core/app/dispatcher.(*DefaultDispatcher).Dispatch(
0xc0017ea360, {0x1563828, 0xc0084a8d80}, {0x1563978, 0xc00066994c}, 0x1466, 0x2?)
github.com/xtls/xray-core/app/dispatcher/default.go:266 +0x325
github.com/xtls/xray-core/common/mux.(*Server).Dispatch(
0x1563860?, {0x1563828?, 0xc0084a8d80?}, {0x1563978?, 0xc00066994c?}, 0x995?, 0xc??})
github.com/xtls/xray-core/common/mux/server.go:41 +0xc6
github.com/xtls/xray-core/proxy/vless/inbound.(*Handler).Process(
0xc001580590, {0x1563828, 0xc0084a8b70}, 0x1544108?, {0x156a718, 0xc0084a8b10}, {0x1565c40, 0x0000336c0})
github.com/xtls/xray-core/proxy/vless/inbound/inbound.go:523 +0x1d59
github.com/xtls/xray-core/app/proxyman/inbound.(*tcpWorker).callback(
0xc000b94500, {0x156a980, 0xc006a1b40})
github.com/xtls/xray-core/app/proxyman/inbound/worker.go:109 +0x5e7
created by github.com/xtls/xray-core/app/proxyman/inbound.(*tcpWorker).Start.func1
in goroutine 1205978
github.com/xtls/xray-core/app/proxyman/inbound/worker.go:123 +0x7a
@iambabyninja can you try if this fix the issue? https://github.com/XTLS/Xray-core/actions/runs/12577069437