Class: ScoutApm::Instruments::PercentileSampler

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/percentile_sampler.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ PercentileSampler

Returns a new instance of PercentileSampler.



21
22
23
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 21

def initialize(context)
  @context = context
end

Instance Method Details

#histogramsObject



25
26
27
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 25

def histograms
  @context.request_histograms_by_time
end

#human_nameObject



33
34
35
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 33

def human_name
  'Percentiles'
end

#loggerObject



29
30
31
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 29

def logger
  @context.logger
end

#metrics(timestamp, store) ⇒ Object



37
38
39
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 37

def metrics(timestamp, store)
  store.track_histograms!(percentiles(timestamp), :timestamp => timestamp)
end

#percentiles(time) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 41

def percentiles(time)
  result = []

  histogram = histograms.delete(time)

  return result unless histogram

  histogram.each_name do |name|
    result << HistogramReport.new(name, histogram.raw(name))
  end

  result
end