class ScoutApm::ExternalServiceMetricSet

Attributes

metrics[R]

Public Class Methods

new(context) click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 17
def initialize(context)
  @context = context

  # A hash of ExternalServiceMetricStats values, keyed by ExternalServiceMetricStats.key
  @metrics = Hash.new
end

Public Instance Methods

<<(stat) click to toggle source

Add a single ExternalServiceMetricStats object to this set.

Looks up an existing one under this key and merges, or just saves a new one under the key

# File lib/scout_apm/external_service_metric_set.rb, line 54
def <<(stat)
  existing_stat = metrics[stat.key]
  if existing_stat
    existing_stat.combine!(stat)
  elsif at_limit?
    # We're full up, can't add any more.
    # Should I log this? It may get super noisy?
  else
    metrics[stat.key] = stat
  end
end
at_limit?() click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 91
def at_limit?
  @limit ||= context.config.value('external_service_metric_limit')
  metrics.size >= @limit
end
combine!(other) click to toggle source

Take another set, and merge it with this one

# File lib/scout_apm/external_service_metric_set.rb, line 43
def combine!(other)
  other.each do |metric|
    self << metric
  end
  self
end
context() click to toggle source

Need to look this up again if we end up as nil. Which I guess can happen after a Marshal load?

# File lib/scout_apm/external_service_metric_set.rb, line 26
def context
  @context ||= ScoutApm::Agent.instance.context
end
each() { |external_service_metric_stat| ... } click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 30
def each
  metrics.each do |_key, external_service_metric_stat|
    yield external_service_metric_stat
  end
end
increment_transaction_count!() click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 66
def increment_transaction_count!
  metrics.each do |_key, external_service_metric_stat|
    external_service_metric_stat.increment_transaction_count!
  end
end
inspect() click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 85
def inspect
  metrics.map {|key, metric|
    "#{key.inspect} - Count: #{metric.call_count}, Total Time: #{"%.2f" % metric.call_time}"
  }.join("\n")
end
lookup(other) click to toggle source

Looks up a ExternalServiceMetricStats instance in the +@metrics+ hash. Sets the value to other if no key Returns a ExternalServiceMetricStats instance

# File lib/scout_apm/external_service_metric_set.rb, line 38
def lookup(other)
  metrics[other.key] ||= other
end
marshal_dump() click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 8
def marshal_dump
  [ @metrics ]
end
marshal_load(array) click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 12
def marshal_load(array)
  @metrics = array.first
  @context = ScoutApm::Agent.instance.context
end
metrics_to_report() click to toggle source
# File lib/scout_apm/external_service_metric_set.rb, line 72
def metrics_to_report
  report_limit = context.config.value('external_service_metric_report_limit')
  if metrics.size > report_limit
    metrics.
      values.
      sort_by {|stat| stat.call_time }.
      reverse.
      take(report_limit)
  else
    metrics.values
  end
end