Files
Xray-core/main/commands/all/api/stats_online.go
T

52 lines
1.2 KiB
Go
Raw Normal View History

2024-11-03 17:44:15 +04:00
package api
import (
statsService "github.com/xtls/xray-core/app/stats/command"
"github.com/xtls/xray-core/main/commands/base"
)
var cmdOnlineStats = &base.Command{
CustomFlags: true,
2025-02-18 05:06:39 -03:30
UsageLine: "{{.Exec}} api statsonline [--server=127.0.0.1:8080] [-email '']",
Short: "Retrieve the online session count for a user",
2024-11-03 17:44:15 +04:00
Long: `
2025-02-18 05:06:39 -03:30
Retrieve the current number of active sessions for a user from Xray.
2024-11-03 17:44:15 +04:00
Arguments:
2025-02-18 05:06:39 -03:30
-s, -server <server:port>
2024-11-03 17:44:15 +04:00
The API server address. Default 127.0.0.1:8080
2025-02-18 05:06:39 -03:30
-t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
2024-11-03 17:44:15 +04:00
-email
2025-02-18 05:06:39 -03:30
The user's email address.
2024-11-03 17:44:15 +04:00
Example:
2025-02-18 05:06:39 -03:30
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -email "xray@love.com"
2024-11-03 17:44:15 +04:00
`,
Run: executeOnlineStats,
}
func executeOnlineStats(cmd *base.Command, args []string) {
setSharedFlags(cmd)
email := cmd.Flag.String("email", "", "")
cmd.Flag.Parse(args)
statName := "user>>>" + *email + ">>>online"
conn, ctx, close := dialAPIServer()
defer close()
client := statsService.NewStatsServiceClient(conn)
r := &statsService.GetStatsRequest{
Name: statName,
Reset_: false,
}
resp, err := client.GetStatsOnline(ctx, r)
if err != nil {
base.Fatalf("failed to get stats: %s", err)
}
showJSONResponse(resp)
}