Skip to content

Commit

Permalink
Make node-status -short work without node stats
Browse files Browse the repository at this point in the history
  • Loading branch information
mlafeldt committed Aug 29, 2016
1 parent 385552d commit 464e1c8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@ func (c *NodeStatusCommand) Run(args []string) int {
}

func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int {
// Get the host stats
hostStats, nodeStatsErr := client.Nodes().Stats(node.ID, nil)
if nodeStatsErr != nil {
c.Ui.Output("")
c.Ui.Error(fmt.Sprintf("error fetching node stats (HINT: ensure Client.Advertise.HTTP is set): %v", nodeStatsErr))
}

// Format the header output
basic := []string{
fmt.Sprintf("ID|%s", limit(node.ID, c.length)),
Expand All @@ -300,13 +293,22 @@ func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int {
fmt.Sprintf("Drain|%v", node.Drain),
fmt.Sprintf("Status|%s", node.Status),
}
if hostStats != nil {
uptime := time.Duration(hostStats.Uptime * uint64(time.Second))
basic = append(basic, fmt.Sprintf("Uptime|%s", uptime.String()))
}
c.Ui.Output(c.Colorize().Color(formatKV(basic)))

if !c.short {
if c.short {
c.Ui.Output(c.Colorize().Color(formatKV(basic)))
} else {
// Get the host stats
hostStats, nodeStatsErr := client.Nodes().Stats(node.ID, nil)
if nodeStatsErr != nil {
c.Ui.Output("")
c.Ui.Error(fmt.Sprintf("error fetching node stats (HINT: ensure Client.Advertise.HTTP is set): %v", nodeStatsErr))
}
if hostStats != nil {
uptime := time.Duration(hostStats.Uptime * uint64(time.Second))
basic = append(basic, fmt.Sprintf("Uptime|%s", uptime.String()))
}
c.Ui.Output(c.Colorize().Color(formatKV(basic)))

// Get list of running allocations on the node
runningAllocs, err := getRunningAllocs(client, node.ID)
if err != nil {
Expand Down

0 comments on commit 464e1c8

Please sign in to comment.