mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
v1.1.0
This commit is contained in:
parent
ed8d6d743c
commit
16544c18ab
627 changed files with 3247 additions and 2635 deletions
23
main/commands/all/api/api.go
Normal file
23
main/commands/all/api/api.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
// CmdAPI calls an API in an Xray process
|
||||
var CmdAPI = &base.Command{
|
||||
UsageLine: "{{.Exec}} api",
|
||||
Short: "Call an API in an Xray process",
|
||||
Long: `{{.Exec}} {{.LongName}} provides tools to manipulate Xray via its API.
|
||||
`,
|
||||
Commands: []*base.Command{
|
||||
cmdRestartLogger,
|
||||
cmdGetStats,
|
||||
cmdQueryStats,
|
||||
cmdSysStats,
|
||||
cmdAddInbounds,
|
||||
cmdAddOutbounds,
|
||||
cmdRemoveInbounds,
|
||||
cmdRemoveOutbounds,
|
||||
},
|
||||
}
|
73
main/commands/all/api/inbounds_add.go
Normal file
73
main/commands/all/api/inbounds_add.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
handlerService "github.com/xtls/xray-core/app/proxyman/command"
|
||||
"github.com/xtls/xray-core/infra/conf"
|
||||
"github.com/xtls/xray-core/infra/conf/serial"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdAddInbounds = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api adi [--server=127.0.0.1:8080] <c1.json> [c2.json]...",
|
||||
Short: "Add inbounds",
|
||||
Long: `
|
||||
Add inbounds to Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
|
||||
`,
|
||||
Run: executeAddInbounds,
|
||||
}
|
||||
|
||||
func executeAddInbounds(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
unnamedArgs := cmd.Flag.Args()
|
||||
if len(unnamedArgs) == 0 {
|
||||
fmt.Println("reading from stdin:")
|
||||
unnamedArgs = []string{"stdin:"}
|
||||
}
|
||||
|
||||
ins := make([]conf.InboundDetourConfig, 0)
|
||||
for _, arg := range unnamedArgs {
|
||||
r, err := loadArg(arg)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to load %s: %s", arg, err)
|
||||
}
|
||||
conf, err := serial.DecodeJSONConfig(r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode %s: %s", arg, err)
|
||||
}
|
||||
ins = append(ins, conf.InboundConfigs...)
|
||||
}
|
||||
if len(ins) == 0 {
|
||||
base.Fatalf("no valid inbound found")
|
||||
}
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := handlerService.NewHandlerServiceClient(conn)
|
||||
for _, in := range ins {
|
||||
fmt.Println("adding:", in.Tag)
|
||||
i, err := in.Build()
|
||||
if err != nil {
|
||||
base.Fatalf("failed to build conf: %s", err)
|
||||
}
|
||||
r := &handlerService.AddInboundRequest{
|
||||
Inbound: i,
|
||||
}
|
||||
resp, err := client.AddInbound(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to add inbound: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
||||
}
|
74
main/commands/all/api/inbounds_remove.go
Normal file
74
main/commands/all/api/inbounds_remove.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
handlerService "github.com/xtls/xray-core/app/proxyman/command"
|
||||
"github.com/xtls/xray-core/infra/conf/serial"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdRemoveInbounds = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api rmi [--server=127.0.0.1:8080] <json_file|tag> [json_file] [tag]...",
|
||||
Short: "Remove inbounds",
|
||||
Long: `
|
||||
Remove inbounds from Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
|
||||
`,
|
||||
Run: executeRemoveInbounds,
|
||||
}
|
||||
|
||||
func executeRemoveInbounds(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
unnamedArgs := cmd.Flag.Args()
|
||||
if len(unnamedArgs) == 0 {
|
||||
fmt.Println("reading from stdin:")
|
||||
unnamedArgs = []string{"stdin:"}
|
||||
}
|
||||
|
||||
tags := make([]string, 0)
|
||||
for _, arg := range unnamedArgs {
|
||||
if r, err := loadArg(arg); err == nil {
|
||||
conf, err := serial.DecodeJSONConfig(r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode %s: %s", arg, err)
|
||||
}
|
||||
ins := conf.InboundConfigs
|
||||
for _, i := range ins {
|
||||
tags = append(tags, i.Tag)
|
||||
}
|
||||
} else {
|
||||
// take request as tag
|
||||
tags = append(tags, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tags) == 0 {
|
||||
base.Fatalf("no inbound to remove")
|
||||
}
|
||||
fmt.Println("removing inbounds:", tags)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := handlerService.NewHandlerServiceClient(conn)
|
||||
for _, tag := range tags {
|
||||
fmt.Println("removing:", tag)
|
||||
r := &handlerService.RemoveInboundRequest{
|
||||
Tag: tag,
|
||||
}
|
||||
resp, err := client.RemoveInbound(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to remove inbound: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
||||
}
|
37
main/commands/all/api/logger_restart.go
Normal file
37
main/commands/all/api/logger_restart.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
logService "github.com/xtls/xray-core/app/log/command"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdRestartLogger = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api restartlogger [--server=127.0.0.1:8080]",
|
||||
Short: "Restart the logger",
|
||||
Long: `
|
||||
Restart the logger of Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
`,
|
||||
Run: executeRestartLogger,
|
||||
}
|
||||
|
||||
func executeRestartLogger(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := logService.NewLoggerServiceClient(conn)
|
||||
r := &logService.RestartLoggerRequest{}
|
||||
resp, err := client.RestartLogger(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to restart logger: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
73
main/commands/all/api/outbounds_add.go
Normal file
73
main/commands/all/api/outbounds_add.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
handlerService "github.com/xtls/xray-core/app/proxyman/command"
|
||||
"github.com/xtls/xray-core/infra/conf"
|
||||
"github.com/xtls/xray-core/infra/conf/serial"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdAddOutbounds = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api ado [--server=127.0.0.1:8080] <c1.json> [c2.json]...",
|
||||
Short: "Add outbounds",
|
||||
Long: `
|
||||
Add outbounds to Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
|
||||
`,
|
||||
Run: executeAddOutbounds,
|
||||
}
|
||||
|
||||
func executeAddOutbounds(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
unnamedArgs := cmd.Flag.Args()
|
||||
if len(unnamedArgs) == 0 {
|
||||
fmt.Println("Reading from STDIN")
|
||||
unnamedArgs = []string{"stdin:"}
|
||||
}
|
||||
|
||||
outs := make([]conf.OutboundDetourConfig, 0)
|
||||
for _, arg := range unnamedArgs {
|
||||
r, err := loadArg(arg)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to load %s: %s", arg, err)
|
||||
}
|
||||
conf, err := serial.DecodeJSONConfig(r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode %s: %s", arg, err)
|
||||
}
|
||||
outs = append(outs, conf.OutboundConfigs...)
|
||||
}
|
||||
if len(outs) == 0 {
|
||||
base.Fatalf("no valid outbound found")
|
||||
}
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := handlerService.NewHandlerServiceClient(conn)
|
||||
for _, out := range outs {
|
||||
fmt.Println("adding:", out.Tag)
|
||||
o, err := out.Build()
|
||||
if err != nil {
|
||||
base.Fatalf("failed to build conf: %s", err)
|
||||
}
|
||||
r := &handlerService.AddOutboundRequest{
|
||||
Outbound: o,
|
||||
}
|
||||
resp, err := client.AddOutbound(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to add outbound: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
||||
}
|
73
main/commands/all/api/outbounds_remove.go
Normal file
73
main/commands/all/api/outbounds_remove.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
handlerService "github.com/xtls/xray-core/app/proxyman/command"
|
||||
"github.com/xtls/xray-core/infra/conf/serial"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdRemoveOutbounds = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api rmo [--server=127.0.0.1:8080] <json_file|tag> [json_file] [tag]...",
|
||||
Short: "Remove outbounds",
|
||||
Long: `
|
||||
Remove outbounds from Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
|
||||
`,
|
||||
Run: executeRemoveOutbounds,
|
||||
}
|
||||
|
||||
func executeRemoveOutbounds(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
unnamedArgs := cmd.Flag.Args()
|
||||
if len(unnamedArgs) == 0 {
|
||||
fmt.Println("reading from stdin:")
|
||||
unnamedArgs = []string{"stdin:"}
|
||||
}
|
||||
|
||||
tags := make([]string, 0)
|
||||
for _, arg := range unnamedArgs {
|
||||
if r, err := loadArg(arg); err == nil {
|
||||
conf, err := serial.DecodeJSONConfig(r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode %s: %s", arg, err)
|
||||
}
|
||||
outs := conf.OutboundConfigs
|
||||
for _, o := range outs {
|
||||
tags = append(tags, o.Tag)
|
||||
}
|
||||
} else {
|
||||
// take request as tag
|
||||
tags = append(tags, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tags) == 0 {
|
||||
base.Fatalf("no outbound to remove")
|
||||
}
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := handlerService.NewHandlerServiceClient(conn)
|
||||
for _, tag := range tags {
|
||||
fmt.Println("removing:", tag)
|
||||
r := &handlerService.RemoveOutboundRequest{
|
||||
Tag: tag,
|
||||
}
|
||||
resp, err := client.RemoveOutbound(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to remove outbound: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
||||
}
|
119
main/commands/all/api/shared.go
Normal file
119
main/commands/all/api/shared.go
Normal file
|
@ -0,0 +1,119 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
type serviceHandler func(ctx context.Context, conn *grpc.ClientConn, cmd *base.Command, args []string) string
|
||||
|
||||
var (
|
||||
apiServerAddrPtr string
|
||||
apiTimeout int
|
||||
)
|
||||
|
||||
func setSharedFlags(cmd *base.Command) {
|
||||
cmd.Flag.StringVar(&apiServerAddrPtr, "s", "127.0.0.1:8080", "")
|
||||
cmd.Flag.StringVar(&apiServerAddrPtr, "server", "127.0.0.1:8080", "")
|
||||
cmd.Flag.IntVar(&apiTimeout, "t", 3, "")
|
||||
cmd.Flag.IntVar(&apiTimeout, "timeout", 3, "")
|
||||
}
|
||||
|
||||
func dialAPIServer() (conn *grpc.ClientConn, ctx context.Context, close func()) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(apiTimeout)*time.Second)
|
||||
conn, err := grpc.DialContext(ctx, apiServerAddrPtr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
base.Fatalf("failed to dial %s", apiServerAddrPtr)
|
||||
}
|
||||
close = func() {
|
||||
cancel()
|
||||
conn.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// loadArg loads one arg, maybe an remote url, or local file path
|
||||
func loadArg(arg string) (out io.Reader, err error) {
|
||||
var data []byte
|
||||
switch {
|
||||
case strings.HasPrefix(arg, "http://"), strings.HasPrefix(arg, "https://"):
|
||||
data, err = fetchHTTPContent(arg)
|
||||
|
||||
case arg == "stdin:":
|
||||
data, err = ioutil.ReadAll(os.Stdin)
|
||||
|
||||
default:
|
||||
data, err = ioutil.ReadFile(arg)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
out = bytes.NewBuffer(data)
|
||||
return
|
||||
}
|
||||
|
||||
// fetchHTTPContent dials https for remote content
|
||||
func fetchHTTPContent(target string) ([]byte, error) {
|
||||
parsedTarget, err := url.Parse(target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if s := strings.ToLower(parsedTarget.Scheme); s != "http" && s != "https" {
|
||||
return nil, fmt.Errorf("invalid scheme: %s", parsedTarget.Scheme)
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
resp, err := client.Do(&http.Request{
|
||||
Method: "GET",
|
||||
URL: parsedTarget,
|
||||
Close: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial to %s", target)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
content, err := buf.ReadAllToBytes(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read HTTP response")
|
||||
}
|
||||
|
||||
return content, nil
|
||||
}
|
||||
|
||||
func showResponese(m proto.Message) {
|
||||
msg := ""
|
||||
bs, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
} else {
|
||||
msg = string(bs)
|
||||
msg = strings.TrimSpace(msg)
|
||||
}
|
||||
if msg == "" {
|
||||
return
|
||||
}
|
||||
fmt.Println(msg)
|
||||
}
|
48
main/commands/all/api/stats_get.go
Normal file
48
main/commands/all/api/stats_get.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
statsService "github.com/xtls/xray-core/app/stats/command"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdGetStats = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api stats [--server=127.0.0.1:8080] [-name '']",
|
||||
Short: "Get statistics",
|
||||
Long: `
|
||||
Get statistics from Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
-name
|
||||
Name of the stat counter.
|
||||
-reset
|
||||
Reset the counter to fetching its value.
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -name "inbound>>>statin>>>traffic>>>downlink"
|
||||
`,
|
||||
Run: executeGetStats,
|
||||
}
|
||||
|
||||
func executeGetStats(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
statName := cmd.Flag.String("name", "", "")
|
||||
reset := cmd.Flag.Bool("reset", false, "")
|
||||
cmd.Flag.Parse(args)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := statsService.NewStatsServiceClient(conn)
|
||||
r := &statsService.GetStatsRequest{
|
||||
Name: *statName,
|
||||
Reset_: *reset,
|
||||
}
|
||||
resp, err := client.GetStats(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to get stats: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
48
main/commands/all/api/stats_query.go
Normal file
48
main/commands/all/api/stats_query.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
statsService "github.com/xtls/xray-core/app/stats/command"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdQueryStats = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api statsquery [--server=127.0.0.1:8080] [-pattern '']",
|
||||
Short: "Query statistics",
|
||||
Long: `
|
||||
Query statistics from Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
-pattern
|
||||
Pattern of the query.
|
||||
-reset
|
||||
Reset the counter to fetching its value.
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -pattern "counter_"
|
||||
`,
|
||||
Run: executeQueryStats,
|
||||
}
|
||||
|
||||
func executeQueryStats(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
pattern := cmd.Flag.String("pattern", "", "")
|
||||
reset := cmd.Flag.Bool("reset", false, "")
|
||||
cmd.Flag.Parse(args)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := statsService.NewStatsServiceClient(conn)
|
||||
r := &statsService.QueryStatsRequest{
|
||||
Pattern: *pattern,
|
||||
Reset_: *reset,
|
||||
}
|
||||
resp, err := client.QueryStats(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to query stats: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
37
main/commands/all/api/stats_sys.go
Normal file
37
main/commands/all/api/stats_sys.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
statsService "github.com/xtls/xray-core/app/stats/command"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdSysStats = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api statssys [--server=127.0.0.1:8080]",
|
||||
Short: "Get system statistics",
|
||||
Long: `
|
||||
Get system statistics from Xray.
|
||||
Arguments:
|
||||
-s, -server
|
||||
The API server address. Default 127.0.0.1:8080
|
||||
-t, -timeout
|
||||
Timeout seconds to call API. Default 3
|
||||
`,
|
||||
Run: executeSysStats,
|
||||
}
|
||||
|
||||
func executeSysStats(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
cmd.Flag.Parse(args)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := statsService.NewStatsServiceClient(conn)
|
||||
r := &statsService.SysStatsRequest{}
|
||||
resp, err := client.GetSysStats(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to get sys stats: %s", err)
|
||||
}
|
||||
showResponese(resp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue