github.com/xraypb/Xray-core@v1.8.1/main/commands/all/api/stats_query.go (about) 1 package api 2 3 import ( 4 statsService "github.com/xraypb/Xray-core/app/stats/command" 5 "github.com/xraypb/Xray-core/main/commands/base" 6 ) 7 8 var cmdQueryStats = &base.Command{ 9 CustomFlags: true, 10 UsageLine: "{{.Exec}} api statsquery [--server=127.0.0.1:8080] [-pattern '']", 11 Short: "Query statistics", 12 Long: ` 13 Query statistics from Xray. 14 Arguments: 15 -s, -server 16 The API server address. Default 127.0.0.1:8080 17 -t, -timeout 18 Timeout seconds to call API. Default 3 19 -pattern 20 Pattern of the query. 21 -reset 22 Reset the counter to fetching its value. 23 Example: 24 {{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -pattern "counter_" 25 `, 26 Run: executeQueryStats, 27 } 28 29 func executeQueryStats(cmd *base.Command, args []string) { 30 setSharedFlags(cmd) 31 pattern := cmd.Flag.String("pattern", "", "") 32 reset := cmd.Flag.Bool("reset", false, "") 33 cmd.Flag.Parse(args) 34 35 conn, ctx, close := dialAPIServer() 36 defer close() 37 38 client := statsService.NewStatsServiceClient(conn) 39 r := &statsService.QueryStatsRequest{ 40 Pattern: *pattern, 41 Reset_: *reset, 42 } 43 resp, err := client.QueryStats(ctx, r) 44 if err != nil { 45 base.Fatalf("failed to query stats: %s", err) 46 } 47 showJSONResponse(resp) 48 }