Skip to content

API: Add user online stats #3637

Merged
yuhan6665 merged 9 commits intoXTLS:mainfrom
hossinasaadi:OnlineCount
Nov 3, 2024
Merged

API: Add user online stats #3637
yuhan6665 merged 9 commits intoXTLS:mainfrom
hossinasaadi:OnlineCount

Conversation

@hossinasaadi
Copy link
Contributor

implement custom counter for ips connected to each client by email

  1. add statsUserOnline to config.json add statsUserOnline bool to policy
      "levels": {
        "0": {
          "statsUserDownlink": true,
          "statsUserUplink": true,
**        "statsUserOnline": true

        },  
  1. each ip will remain in list for 20 sec (may we can add custom value to config) 0b8ad84
  2. client should have an email.
  3. get user online from api :
./xray api statsonline -server=127.0.0.1:8080 -email "user1@test.com"
{
   "stat":  {
       "name":  "user>>>user1@test.com>>>online",
       "value":  "3"
   }
}

this implementation based on #2277 (comment) discussion and may needs some review to improve and suggestions.
@mmmray @yuhan6665

@mmmray
Copy link
Contributor

mmmray commented Aug 4, 2024

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.

hossinasaadi and others added 2 commits August 5, 2024 09:37
Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>
@APT-ZERO
Copy link

APT-ZERO commented Aug 5, 2024

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)

@yuhan6665
Copy link
Member

Looks good to me! Thanks for the effort to move to API solution. I will close #2277 for now

@hossinasaadi
Copy link
Contributor Author

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.

@yuhan6665 yuhan6665 changed the title Add user online stats API: Add user online stats Aug 6, 2024
@RPRX
Copy link
Member

RPRX commented Aug 7, 2024

#3644 (comment)

@willstore69
Copy link

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.

@yuhan6665
Copy link
Member

@hossinasaadi Can you help to resolve conflict? I think it is time to merge

@M03ED
Copy link
Contributor

M03ED commented Dec 13, 2024

is it possible to get all users online stats with single request ?

@iambabyninja
Copy link
Member

iambabyninja commented Dec 31, 2024

@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

@yuhan6665
Copy link
Member

it2konst pushed a commit to it2konst/gametunnel-core that referenced this pull request Mar 1, 2026
* add statsUserOnline bool to policy

* add OnlineMap struct to stats

* apply UserOnline functionality to dispatcher

* add statsonline api command

* fix comments

* Update app/stats/online_map.go

Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>

* improve AddIP

* regenerate pb

---------

Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>
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.

8 participants