From 8d82258e4cf29b49735434b7892bb4a91b05d706 Mon Sep 17 00:00:00 2001 From: Rick Sherman Date: Tue, 10 May 2016 17:22:14 -0500 Subject: [PATCH] (WIP) (RE-7014) Add tracking of gets This adds the statsd tracking of pool gets. It is seemingly working on success, but not fail. WIP --- lib/vmpooler/api.rb | 3 ++- lib/vmpooler/api/v1.rb | 20 ++++++++++++++++++++ vmpooler | 6 +++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/vmpooler/api.rb b/lib/vmpooler/api.rb index ee51cbc..45a9bfa 100644 --- a/lib/vmpooler/api.rb +++ b/lib/vmpooler/api.rb @@ -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 diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 1046593..81500b4 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -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 @@ -79,6 +89,12 @@ module Vmpooler result['ok'] = false end + if result['ok'] + statsd.increment(statsd_prefix + '.checkout_success.' + template, 1) + else + statsd.increment(statsd_prefix + '.checkout_fail.' + template, 1) + end + result end @@ -366,6 +382,10 @@ module Vmpooler result['domain'] = config['domain'] end + if !result['ok'] + statsd.increment(statsd_prefix + '.checkout_fail.' + key, 1) + end + JSON.pretty_generate(result) end diff --git a/vmpooler b/vmpooler index 96b46a1..44ef89c 100755 --- a/vmpooler +++ b/vmpooler @@ -17,7 +17,11 @@ end api = Thread.new { thr = Vmpooler::API.new - thr.helpers.configure(config, Vmpooler.new_redis(redis_host)) + if statsd + thr.helpers.configure(config, Vmpooler.new_redis(redis_host), Vmpooler.new_statsd(statsd, statsd_port)) + else + thr.helpers.configure(config, Vmpooler.new_redis(redis_host), statsd=nil) + end thr.helpers.execute! }