Class: ScoutApm::MetricSet

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

Constant Summary collapse

PASSTHROUGH_METRICS =

We can’t aggregate a handful of things like samplers (CPU, Memory), or Controller, and Percentiles so pass through these metrics directly

TODO: Figure out a way to not have this duplicate what’s in Samplers, and also on server’s ingest

["CPU", "Memory", "Instance", "Controller", "SlowTransaction", "Percentile", "Job"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetricSet

Returns a new instance of MetricSet.



11
12
13
# File 'lib/scout_apm/metric_set.rb', line 11

def initialize
  @metrics = Hash.new
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



9
10
11
# File 'lib/scout_apm/metric_set.rb', line 9

def metrics
  @metrics
end

Instance Method Details

#absorb(metric) ⇒ Object

Absorbs a single new metric into the aggregates



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scout_apm/metric_set.rb', line 20

def absorb(metric)
  meta, stat = metric

  if PASSTHROUGH_METRICS.include?(meta.type) # Leave as-is, don't attempt to combine into an /all key
    @metrics[meta] ||= MetricStats.new
    @metrics[meta].combine!(stat)

  elsif meta.type == "Errors" # Sadly special cased, we want both raw and aggregate values
    # When combining MetricSets between different 
      @metrics[meta] ||= MetricStats.new
      @metrics[meta].combine!(stat)

    if !@combine_in_progress
      agg_meta = MetricMeta.new("Errors/Request", :scope => meta.scope)
      @metrics[agg_meta] ||= MetricStats.new
      @metrics[agg_meta].combine!(stat)
    end

  else # Combine down to a single /all key
    agg_meta = MetricMeta.new("#{meta.type}/all", :scope => meta.scope)
    @metrics[agg_meta] ||= MetricStats.new
    @metrics[agg_meta].combine!(stat)
  end
end

#absorb_all(metrics) ⇒ Object



15
16
17
# File 'lib/scout_apm/metric_set.rb', line 15

def absorb_all(metrics)
  Array(metrics).each { |m| absorb(m) }
end

#combine!(other) ⇒ Object

Sets a combine_in_progress flag to prevent double-counting Error metrics. Without it, the Errors/Request number would be increasingly off as metric_sets get merged in.



48
49
50
51
52
53
# File 'lib/scout_apm/metric_set.rb', line 48

def combine!(other)
  @combine_in_progress = true
  absorb_all(other.metrics)
  @combine_in_progress = false
  self
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


56
57
58
# File 'lib/scout_apm/metric_set.rb', line 56

def eql?(other)
  metrics == other.metrics
end