Class: ScoutApm::Instruments::PercentileSampler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, percentiles) ⇒ PercentileSampler

Returns a new instance of PercentileSampler.



8
9
10
11
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 8

def initialize(logger, percentiles)
  @logger = logger
  @percentiles = Array(percentiles)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 4

def logger
  @logger
end

#percentilesObject (readonly)

Returns the value of attribute percentiles.



6
7
8
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 6

def percentiles
  @percentiles
end

Instance Method Details

#human_nameObject



13
14
15
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 13

def human_name
  "Percentiles"
end

#metrics(time) ⇒ Object

Gets the 95th%ile for the time requested



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scout_apm/instruments/percentile_sampler.rb', line 18

def metrics(time)
  ms = {}
  histos = ScoutApm::Agent.instance.request_histograms_by_time[time]
  histos.each_name do |name|
    percentiles.each do |percentile|
      meta = MetricMeta.new("Percentile/#{percentile}/#{name}")
      stat = MetricStats.new
      stat.update!(histos.quantile(name, percentile))
      ms[meta] = stat
    end
  end

  # Wipe the histograms we just collected data on
  ScoutApm::Agent.instance.request_histograms_by_time.delete(time)

  ms
end