From 28b27a4d812cc70acd0b380400c96fb48fef9ac3 Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Wed, 11 Oct 2017 21:08:15 +0800 Subject: [PATCH] pdctl support health check --- pdctl/command/health_command.go | 44 +++++++++++++++++++++++++++++++++ pdctl/ctl.go | 1 + 2 files changed, 45 insertions(+) create mode 100644 pdctl/command/health_command.go diff --git a/pdctl/command/health_command.go b/pdctl/command/health_command.go new file mode 100644 index 00000000000..4da41ceae5a --- /dev/null +++ b/pdctl/command/health_command.go @@ -0,0 +1,44 @@ +// Copyright 2017 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package command + +import ( + "fmt" + "net/http" + + "github.com/spf13/cobra" +) + +var ( + healthPrefix = "health" +) + +// NewHealthCommand return a health subcommand of rootCmd +func NewHealthCommand() *cobra.Command { + m := &cobra.Command{ + Use: "health", + Short: "show the health information", + Run: showHealthCommandFunc, + } + return m +} + +func showHealthCommandFunc(cmd *cobra.Command, args []string) { + r, err := doRequest(cmd, healthPrefix, http.MethodGet) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(r) +} diff --git a/pdctl/ctl.go b/pdctl/ctl.go index 899e962bcbc..793ebda770f 100644 --- a/pdctl/ctl.go +++ b/pdctl/ctl.go @@ -51,6 +51,7 @@ func init() { command.NewHotSpotCommand(), command.NewClusterCommand(), command.NewNamespaceCommand(), + command.NewHealthCommand(), ) cobra.EnablePrefixMatching = true }