module ServiceTemplate::StatsDTimer

Public Class Methods

included(base) click to toggle source
# File lib/service_template/stats_d_timer.rb, line 22
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

report_time(timer_name, sample_rate: 1) { || ... } click to toggle source
# File lib/service_template/stats_d_timer.rb, line 3
def report_time(timer_name, sample_rate: 1)
  if (Time.now.to_f * 1000).to_i % sample_rate == 0
    start_time = Time.now
    yield
    response_time = (Time.now - start_time) * 1000 # statsd reports timers in milliseconds
    ServiceTemplate::Stats.emitter.timing(timer_name, response_time)
  else
    yield
  end
end