github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/command/agent_info.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type AgentInfoCommand struct { 9 Meta 10 } 11 12 func (c *AgentInfoCommand) Help() string { 13 helpText := ` 14 Usage: nomad agent-info [options] 15 16 Display status information about the local agent. 17 18 General Options: 19 20 ` + generalOptionsUsage() 21 return strings.TrimSpace(helpText) 22 } 23 24 func (c *AgentInfoCommand) Synopsis() string { 25 return "Display status information about the local agent" 26 } 27 28 func (c *AgentInfoCommand) Run(args []string) int { 29 flags := c.Meta.FlagSet("agent-info", FlagSetClient) 30 flags.Usage = func() { c.Ui.Output(c.Help()) } 31 if err := flags.Parse(args); err != nil { 32 return 1 33 } 34 35 // Check that we either got no jobs or exactly one. 36 args = flags.Args() 37 if len(args) > 0 { 38 c.Ui.Error(c.Help()) 39 return 1 40 } 41 42 // Get the HTTP client 43 client, err := c.Meta.Client() 44 if err != nil { 45 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 46 return 1 47 } 48 49 // Query the agent info 50 info, err := client.Agent().Self() 51 if err != nil { 52 c.Ui.Error(fmt.Sprintf("Error querying agent info: %s", err)) 53 return 1 54 } 55 56 var stats map[string]interface{} 57 stats, _ = info["stats"] 58 59 for section, data := range stats { 60 c.Ui.Output(section) 61 d, _ := data.(map[string]interface{}) 62 for k, v := range d { 63 c.Ui.Output(fmt.Sprintf(" %s = %v", k, v)) 64 } 65 } 66 67 return 0 68 }