Module: Napa::StatsDTimer

Defined in:
lib/napa/stats_d_timer.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
# File 'lib/napa/stats_d_timer.rb', line 22

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#report_time(timer_name, sample_rate: 1) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/napa/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
    Napa::Stats.emitter.timing(timer_name, response_time)
  else
    yield
  end
end