Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add user online stats #3637

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

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
Collaborator

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.

app/stats/online_map.go Outdated Show resolved Hide resolved
features/stats/stats.go Show resolved Hide resolved
app/stats/online_map.go Outdated Show resolved Hide resolved
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.

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.

6 participants