Include number of allocations in node-status

We recently ran into an issue on a small percentage of nomad-clients
where the nomad-client was running successfully, but due to a race
condition, could not correctly bind to the docker socket. This caused
all of our nomad jobs to be allocated to a single nomad-client instead
of being spread evenly across our clients. The only way to discover this
was to run `nomad node-status <node>` and count each job allocation per
node.

This can lead to a fairly long debugging process if there are several
nomad-clients. Including the number of allocations for each node in the
`node-status` command would save a large amount of debug time.

```
jake@biscuits [12:08:41] [~]
-> % nomad node-status
ID        Datacenter  Name      Class   Drain  Status  Allocations
2b0aabc5  dc1         biscuits  <none>  false  ready   0
```

```
jake@biscuits [12:08:55] [~]
-> % nomad node-status
ID        Datacenter  Name      Class   Drain  Status  Allocations
2b0aabc5  dc1         biscuits  <none>  false  ready   1
```
This commit is contained in:
Jake Champlin 2016-03-03 12:19:56 -05:00
parent a44127aaa6
commit c4a3f5047b
2 changed files with 14 additions and 5 deletions

View File

@ -20,7 +20,7 @@ dev: format generate
bin: generate
@sh -c "'$(PWD)/scripts/build.sh'"
release:
release:
@$(MAKE) bin
cov:
@ -31,7 +31,7 @@ test: generate
@sh -c "'$(PWD)/scripts/test.sh'"
@$(MAKE) vet
cover:
cover:
go list ./... | xargs -n1 go test --cover
format:

View File

@ -90,15 +90,24 @@ func (c *NodeStatusCommand) Run(args []string) int {
// Format the nodes list
out := make([]string, len(nodes)+1)
out[0] = "ID|Datacenter|Name|Class|Drain|Status"
out[0] = "ID|Datacenter|Name|Class|Drain|Status|Allocations"
for i, node := range nodes {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s",
// Fetch number of allocations per node
nodeAllocs, _, err := client.Nodes().Allocations(node.ID, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error querying node allocations: %s", err))
return 1
}
numAllocs := len(nodeAllocs)
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s|%v",
limit(node.ID, length),
node.Datacenter,
node.Name,
node.NodeClass,
node.Drain,
node.Status)
node.Status,
numAllocs)
}
// Dump the output