From 800d1db73265771896cebe0ae83df56ee01872cf Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Fri, 17 Jun 2016 12:22:17 -0700 Subject: [PATCH] Improve the error messages when obtaining node and alloc stats --- command/alloc_status.go | 2 +- command/node_status.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/command/alloc_status.go b/command/alloc_status.go index 80d816d16..9b88c30b4 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -135,7 +135,7 @@ func (c *AllocStatusCommand) Run(args []string) int { stats, statsErr = client.Allocations().Stats(alloc, nil) if statsErr != nil { c.Ui.Output("") - c.Ui.Error(fmt.Sprintf("couldn't retreive stats: %v", statsErr)) + c.Ui.Error(fmt.Sprintf("couldn't retrieve stats (HINT: ensure Client.Advertise.HTTP is set): %v", statsErr)) } // Format the allocation data diff --git a/command/node_status.go b/command/node_status.go index 9b38d580e..1796c36fc 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -222,6 +222,10 @@ 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{ @@ -257,6 +261,10 @@ func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int { } hostResources, err := getHostResources(hostStats, node) + if err != nil { + c.Ui.Output("") + c.Ui.Error(fmt.Sprintf("error fetching node stats (HINT: ensure Client.Advertise.HTTP is set): %v", err)) + } if err == nil { c.Ui.Output(c.Colorize().Color("\n[bold]Host Resource Utilization[reset]")) c.Ui.Output(formatList(hostResources)) @@ -286,10 +294,6 @@ func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int { if c.verbose { c.formatAttributes(node) } - if nodeStatsErr != nil { - c.Ui.Output("") - c.Ui.Error(fmt.Sprintf("error fetching node stats: %v", nodeStatsErr)) - } return 0 }