(RE-7014) Add support for statsd

They way we were using graphite was incorrect for the type of data we were sending it.  statsd is the appropriate mechanism for our needs.
statsd and graphite are mutually exclusive and configuring statsd will take precendence over Graphite.  Example of configuration in vmpooler.yaml.example
This commit is contained in:
Rick Sherman 2016-05-10 12:47:01 -05:00
parent 5aaab7c5c2
commit 8d75865a5c
8 changed files with 143 additions and 7 deletions

View file

@ -1,12 +1,17 @@
module Vmpooler
class PoolManager
def initialize(config, logger, redis, graphite=nil)
def initialize(config, logger, redis, graphite=nil, statsd=nil)
$config = config
# Load logger library
$logger = logger
unless graphite.nil?
# statsd and graphite are mutex in the context of vmpooler
unless statsd.nil?
$statsd = statsd
end
unless graphite.nil? || !statsd.nil?
$graphite = graphite
end
@ -258,6 +263,7 @@ module Vmpooler
$redis.decr('vmpooler__tasks__clone')
begin
$statsd.timing($config[:statsd]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $statsd
$graphite.log($config[:graphite]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $graphite
rescue
end
@ -565,7 +571,10 @@ module Vmpooler
total = $redis.scard('vmpooler__pending__' + pool['name']) + ready
begin
if defined? $graphite
if defined? $statsd
$statsd.increment($config[:statsd]['prefix'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
$statsd.increment($config[:statsd]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
elsif defined? $graphite
$graphite.log($config[:graphite]['prefix'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
$graphite.log($config[:graphite]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
end

12
lib/vmpooler/statsd.rb Normal file
View file

@ -0,0 +1,12 @@
require 'rubygems' unless defined?(Gem)
module Vmpooler
class Statsd
def initialize(
s = 'statsd',
port = 8125
)
@server = Statsd.new s, port
end
end
end