(RE-7014) Add tracking of vm gets via statsd

Add the tracking of successful, failed, invalid, and empty pool vm gets.  It is possible we may want to tweak this, but have validated with spec tests and pcaps.

```
vmpooler-tmp-dev.ready.debian-7-x86_64:1|c
vmpooler-tmp-dev.running.debian-7-x86_64:1|c

vmpooler-tmp-dev.checkout.invalid:1|c
vmpooler-tmp-dev.checkout.success.debian-7-x86_64:1|c
vmpooler-tmp-dev.checkout.empty:1|c

vmpooler-tmp-dev.running.debian-7-x86_64:1|c

vmpooler-tmp-dev.clone.debian-7-x86_64:12.10|ms

vmpooler-tmp-dev.ready.debian-7-x86_64:1|c
```
This commit is contained in:
Rick Sherman 2016-06-07 23:01:03 -05:00
parent 8d75865a5c
commit b983472088
4 changed files with 90 additions and 17 deletions

View file

@ -42,9 +42,10 @@ module Vmpooler
use Vmpooler::API::Reroute
use Vmpooler::API::V1
def configure(config, redis, environment = :production)
def configure(config, redis, statsd, environment = :production)
self.settings.set :config, config
self.settings.set :redis, redis
self.settings.set :statsd, statsd
self.settings.set :environment, environment
end

View file

@ -12,6 +12,16 @@ module Vmpooler
Vmpooler::API.settings.redis
end
def statsd
Vmpooler::API.settings.statsd
end
def statsd_prefix
if Vmpooler::API.settings.statsd
Vmpooler::API.settings.config[:statsd]['prefix']? Vmpooler::API.settings.config[:statsd]['prefix'] : 'vmpooler'
end
end
def config
Vmpooler::API.settings.config[:config]
end
@ -32,13 +42,16 @@ module Vmpooler
newhash = {}
hash.each do |key, val|
if Vmpooler::API.settings.config[:alias][key]
key = Vmpooler::API.settings.config[:alias][key]
end
if backend.exists('vmpooler__ready__' + key)
newhash[key] = val
elsif backend.exists('vmpooler__empty__' + key)
newhash['empty'] = (newhash['empty'] || 0) + val.to_i
else
if Vmpooler::API.settings.config[:alias][key]
newkey = Vmpooler::API.settings.config[:alias][key]
newhash[newkey] = val
end
newhash['invalid'] = (newhash['invalid'] || 0) + val.to_i
end
end
@ -94,8 +107,10 @@ module Vmpooler
vm = fetch_single_vm(template)
if !vm
failed = true
statsd.increment(statsd_prefix + '.checkout.fail.' + template, 1)
break
else
statsd.increment(statsd_prefix + '.checkout.success.' + template, 1)
vms << [ template, vm ]
end
end
@ -375,8 +390,16 @@ module Vmpooler
content_type :json
result = { 'ok' => false }
if jdata and !jdata.empty?
result = atomically_allocate_vms(jdata)
if jdata
empty = jdata.delete('empty')
invalid = jdata.delete('invalid')
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
if !jdata.empty?
result = atomically_allocate_vms(jdata)
else
status 404
end
else
status 404
end
@ -400,8 +423,16 @@ module Vmpooler
content_type :json
result = { 'ok' => false }
if payload and !payload.empty?
result = atomically_allocate_vms(payload)
if payload
empty = payload.delete('empty')
invalid = payload.delete('invalid')
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
if !payload.empty?
result = atomically_allocate_vms(payload)
else
status 404
end
else
status 404
end