From 385552ddeaf8faeeff99c5733c4e5b7df3e8b046 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Mon, 29 Aug 2016 17:43:09 +0200 Subject: [PATCH 1/2] Make alloc-status -short work without allocation stats --- command/alloc_status.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/command/alloc_status.go b/command/alloc_status.go index c71dd865b2dd..b25dc97d2025 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -204,14 +204,6 @@ func (c *AllocStatusCommand) Run(args []string) int { return 0 } - var statsErr error - var stats *api.AllocResourceUsage - stats, statsErr = client.Allocations().Stats(alloc, nil) - if statsErr != nil { - c.Ui.Output("") - c.Ui.Error(fmt.Sprintf("couldn't retrieve stats (HINT: ensure Client.Advertise.HTTP is set): %v", statsErr)) - } - // Format the allocation data basic := []string{ fmt.Sprintf("ID|%s", limit(alloc.ID, length)), @@ -236,6 +228,13 @@ func (c *AllocStatusCommand) Run(args []string) int { if short { c.shortTaskStatus(alloc) } else { + var statsErr error + var stats *api.AllocResourceUsage + stats, statsErr = client.Allocations().Stats(alloc, nil) + if statsErr != nil { + c.Ui.Output("") + c.Ui.Error(fmt.Sprintf("couldn't retrieve stats (HINT: ensure Client.Advertise.HTTP is set): %v", statsErr)) + } c.outputTaskDetails(alloc, stats, displayStats) } From 464e1c8b781f9155a9539478c8cb712355c8baa5 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Mon, 29 Aug 2016 17:44:23 +0200 Subject: [PATCH 2/2] Make node-status -short work without node stats --- command/node_status.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/command/node_status.go b/command/node_status.go index 688acbc53bab..710b506c68be 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -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)), @@ -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 {