github.com/cilium/cilium@v1.16.2/cilium-health/cmd/get.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package cmd
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"text/tabwriter"
    10  
    11  	"github.com/spf13/cobra"
    12  
    13  	ciliumClient "github.com/cilium/cilium/pkg/client"
    14  	"github.com/cilium/cilium/pkg/command"
    15  )
    16  
    17  // healthGetCmd represents the get command
    18  var healthGetCmd = &cobra.Command{
    19  	Use:     "get",
    20  	Aliases: []string{"inspect", "show"},
    21  	Short:   "Display local cilium agent status",
    22  	Run: func(cmd *cobra.Command, args []string) {
    23  		result, err := client.Restapi.GetHealthz(nil)
    24  		if err != nil {
    25  			Fatalf("Cannot get health for local instance: %s\n", err)
    26  		}
    27  		sr := result.Payload
    28  
    29  		if command.OutputOption() {
    30  			if err := command.PrintOutput(sr); err != nil {
    31  				os.Exit(1)
    32  			}
    33  		} else {
    34  			w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0)
    35  			fmt.Fprintf(w, "Daemon uptime:\t%s\n", sr.Uptime)
    36  			load := sr.SystemLoad
    37  			fmt.Fprintf(w, "Node load:\t%s %s %s\n",
    38  				load.Last1min, load.Last5min, load.Last15min)
    39  			ciliumClient.FormatStatusResponse(w, &sr.Cilium, ciliumClient.StatusNoDetails)
    40  			w.Flush()
    41  		}
    42  	},
    43  }
    44  
    45  func init() {
    46  	rootCmd.AddCommand(healthGetCmd)
    47  	command.AddOutputOption(healthGetCmd)
    48  }