2021-01-29 19:31:11 -05:00
|
|
|
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:
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-s, -server <server:port>
|
2021-01-29 19:31:11 -05:00
|
|
|
The API server address. Default 127.0.0.1:8080
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-t, -timeout <seconds>
|
2021-01-29 19:31:11 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|