1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/main/commands/all/api/balancer_check.go
Jebbs 2523d77919
improve commands
(rebased from ebbf31f07e)
2021-09-04 11:11:45 +01:00

48 lines
1.2 KiB
Go

package api
import (
routerService "github.com/v2fly/v2ray-core/v4/app/router/command"
"github.com/v2fly/v2ray-core/v4/main/commands/base"
)
var cmdBalancerCheck = &base.Command{
CustomFlags: true,
UsageLine: "{{.Exec}} api bc [--server=127.0.0.1:8080] [balancer]...",
Short: "balancer health check",
Long: `
Perform instant health checks for specific balancers. If no
balancer tag specified, check all balancers.
> Make sure you have "RoutingService" set in "config.api.services"
of server config.
Arguments:
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080
-t, -timeout <seconds>
Timeout seconds to call API. Default 3
Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 balancer1 balancer2
`,
Run: executeBalancerCheck,
}
func executeBalancerCheck(cmd *base.Command, args []string) {
setSharedFlags(cmd)
cmd.Flag.Parse(args)
conn, ctx, close := dialAPIServer()
defer close()
client := routerService.NewRoutingServiceClient(conn)
r := &routerService.CheckBalancersRequest{BalancerTags: cmd.Flag.Args()}
_, err := client.CheckBalancers(ctx, r)
if err != nil {
base.Fatalf("failed to perform balancer health checks: %s", err)
}
}