github.com/EagleQL/Xray-core@v1.4.3/main/commands/all/api/stats_get.go (about)

     1  package api
     2  
     3  import (
     4  	statsService "github.com/xtls/xray-core/app/stats/command"
     5  	"github.com/xtls/xray-core/main/commands/base"
     6  )
     7  
     8  var cmdGetStats = &base.Command{
     9  	CustomFlags: true,
    10  	UsageLine:   "{{.Exec}} api stats [--server=127.0.0.1:8080] [-name '']",
    11  	Short:       "Get statistics",
    12  	Long: `
    13  Get 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  	-name
    20  		Name of the stat counter.
    21  	-reset
    22  		Reset the counter to fetching its value.
    23  Example:
    24  	{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -name "inbound>>>statin>>>traffic>>>downlink"
    25  `,
    26  	Run: executeGetStats,
    27  }
    28  
    29  func executeGetStats(cmd *base.Command, args []string) {
    30  	setSharedFlags(cmd)
    31  	statName := cmd.Flag.String("name", "", "")
    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.GetStatsRequest{
    40  		Name:   *statName,
    41  		Reset_: *reset,
    42  	}
    43  	resp, err := client.GetStats(ctx, r)
    44  	if err != nil {
    45  		base.Fatalf("failed to get stats: %s", err)
    46  	}
    47  	showResponese(resp)
    48  }