Class: Metrics::Instruments::PostProcessTimer

Inherits:
Timer
  • Object
show all
Defined in:
lib/ruby-metrics/instruments/post_process_timer.rb

Instance Attribute Summary

Attributes inherited from Timer

#duration_unit, #rate_unit

Instance Method Summary collapse

Methods inherited from Timer

#as_json, #clear, #count, #fifteen_minute_rate, #five_minute_rate, #max, #mean, #mean_rate, #min, #one_minute_rate, #quantiles, #std_dev, #time, #to_json, #values

Methods included from TimeConversion

#convert_to_ns

Constructor Details

#initialize(options = {}) ⇒ PostProcessTimer

Returns a new instance of PostProcessTimer.



6
7
8
9
10
11
12
13
14
# File 'lib/ruby-metrics/instruments/post_process_timer.rb', line 6

def initialize(options = {})
  @meter          = PostProcessMeter.new
  @histogram      = ExponentialHistogram.new

  @duration_unit  = options[:duration_unit] || :seconds
  @rate_unit      = options[:rate_unit] || :seconds

  clear
end

Instance Method Details

#update(timestamp, duration, unit) ⇒ Object



16
17
18
19
# File 'lib/ruby-metrics/instruments/post_process_timer.rb', line 16

def update(timestamp, duration, unit)
  mult = convert_to_ns(1, unit)
  self.update_timer(timestamp, duration * mult)
end

#update_timer(timestamp, duration) ⇒ Object



21
22
23
24
25
26
# File 'lib/ruby-metrics/instruments/post_process_timer.rb', line 21

def update_timer(timestamp, duration)
  if duration >= 0
    @histogram.update(duration)
    @meter.mark timestamp
  end
end