2015-09-11 17:50:39 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-12-12 12:39:16 +00:00
|
|
|
"sort"
|
2015-09-11 17:50:39 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AgentInfoCommand struct {
|
2015-09-14 20:13:52 +00:00
|
|
|
Meta
|
2015-09-11 17:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentInfoCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad agent-info [options]
|
|
|
|
|
2015-09-13 18:39:49 +00:00
|
|
|
Display status information about the local agent.
|
2015-09-11 17:50:39 +00:00
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
General Options:
|
2015-09-11 17:50:39 +00:00
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
` + generalOptionsUsage()
|
2015-09-11 17:50:39 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentInfoCommand) Synopsis() string {
|
2015-09-14 20:13:52 +00:00
|
|
|
return "Display status information about the local agent"
|
2015-09-11 17:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentInfoCommand) Run(args []string) int {
|
2015-09-14 20:13:52 +00:00
|
|
|
flags := c.Meta.FlagSet("agent-info", FlagSetClient)
|
2015-09-11 17:50:39 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we either got no jobs or exactly one.
|
2015-09-14 20:13:52 +00:00
|
|
|
args = flags.Args()
|
|
|
|
if len(args) > 0 {
|
2015-09-11 17:50:39 +00:00
|
|
|
c.Ui.Error(c.Help())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the HTTP client
|
2015-09-14 20:13:52 +00:00
|
|
|
client, err := c.Meta.Client()
|
2015-09-11 17:50:39 +00:00
|
|
|
if err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
2015-09-11 17:50:39 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query the agent info
|
|
|
|
info, err := client.Agent().Self()
|
|
|
|
if err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error querying agent info: %s", err))
|
2015-09-11 17:50:39 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-12-12 12:39:16 +00:00
|
|
|
// Sort and output agent info
|
2015-09-11 17:50:39 +00:00
|
|
|
var stats map[string]interface{}
|
|
|
|
stats, _ = info["stats"]
|
2015-12-12 12:39:16 +00:00
|
|
|
stats_keys := make([]string, 0, len(stats))
|
|
|
|
for key := range stats {
|
|
|
|
stats_keys = append(stats_keys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(stats_keys)
|
|
|
|
|
|
|
|
for _, key := range stats_keys {
|
|
|
|
c.Ui.Output(key)
|
|
|
|
d, _ := stats[key].(map[string]interface{})
|
|
|
|
d_keys := make([]string, 0, len(d))
|
|
|
|
for key := range d {
|
|
|
|
d_keys = append(d_keys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(d_keys)
|
2015-09-11 17:50:39 +00:00
|
|
|
|
2015-12-12 12:39:16 +00:00
|
|
|
for _, key := range d_keys {
|
|
|
|
c.Ui.Output(fmt.Sprintf(" %s = %v", key, d[key]))
|
2015-09-11 17:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|