[QENG-4181] Add per-pool stats to /status API

Prior to this the only per-pool statistics that could be extracted from the API
were a list of empty pools in the "status" section of the returned results of
the `/status` endpoint.

This adds a new "pools" section to the '/status' results which lists, for each
pool, the following results:

 - The number of ready vms in the pool
 - The number of running vms in the pool
 - The number of pending vms in the pool
 - The maximum size of the pool (as specified in the vmpooler configuration)

Example:

```
{
  "boot": {
  "duration": {
    "average": 163.6,
    "min": 65.49,
    "max": 830.07,
    "total": 247744.71000000002
  },
  "count": {
    "total": 1514
  }
  # ...
  "pools": {
    "pool1": {
      "ready":   5,
      "running": 2,
      "pending": 1,
      "max":     15
    },
    "pool2": {
      "ready":   0,
      "running": 10,
      "pending": 0,
      "max:      10
    }
  }
}
```

This includes spec coverage for this change (we could use more specs on `/status` in general); as well as a couple of general spec improvements.
This commit is contained in:
Rick Bradley 2016-09-09 17:00:47 -05:00
parent 1bf0af2ba5
commit 30dc060731
3 changed files with 134 additions and 3 deletions

View file

@ -123,6 +123,7 @@ module Vmpooler
content_type :json
result = {
pools: {},
status: {
ok: true,
message: 'Battle station fully armed and operational.'
@ -136,7 +137,21 @@ module Vmpooler
# Check for empty pools
pools.each do |pool|
if backend.scard('vmpooler__ready__' + pool['name']).to_i == 0
# REMIND: move this out of the API and into the back-end
ready = backend.scard('vmpooler__ready__' + pool['name']).to_i
running = backend.scard('vmpooler__running__' + pool['name']).to_i
pending = backend.scard('vmpooler__pending__' + pool['name']).to_i
max = pool['size']
result[:pools][pool['name']] = {
ready: ready,
running: running,
pending: pending,
max: max
}
# for backwards compatibility, include separate "empty" stats in "status" block
if ready == 0
result[:status][:empty] ||= []
result[:status][:empty].push(pool['name'])