class NewRelic::MetricData

Attributes

metric_spec[R]
stats[RW]

Public Class Methods

new(metric_spec, stats) click to toggle source
# File lib/new_relic/metric_data.rb, line 16
def initialize(metric_spec, stats)
  @original_spec = nil
  @metric_spec = metric_spec
  self.stats = stats
end

Public Instance Methods

eql?(o) click to toggle source
# File lib/new_relic/metric_data.rb, line 22
def eql?(o)
  (metric_spec.eql?(o.metric_spec)) && (stats.eql?(o.stats))
end
hash() click to toggle source
# File lib/new_relic/metric_data.rb, line 26
def hash
  [metric_spec, stats].hash
end
inspect() click to toggle source
# File lib/new_relic/metric_data.rb, line 30
def inspect
  "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}>"
end
metric_spec=(new_spec) click to toggle source

assigns a new metric spec, and retains the old metric spec as @original_spec if it exists currently

# File lib/new_relic/metric_data.rb, line 36
def metric_spec=(new_spec)
  @original_spec = @metric_spec if @metric_spec
  @metric_spec = new_spec
end
original_spec() click to toggle source
# File lib/new_relic/metric_data.rb, line 41
def original_spec
  @original_spec || @metric_spec
end
to_collector_array(encoder = nil) click to toggle source
# File lib/new_relic/metric_data.rb, line 45
def to_collector_array(encoder = nil)
  stat_key = {'name' => metric_spec.name, 'scope' => metric_spec.scope}
  [stat_key, stats_collector_array(stat_key)]
end
to_json(*a) click to toggle source
# File lib/new_relic/metric_data.rb, line 50
def to_json(*a)
  %Q({"metric_spec":#{metric_spec.to_json},"stats":{"total_exclusive_time":#{stats.total_exclusive_time},"min_call_time":#{stats.min_call_time},"call_count":#{stats.call_count},"sum_of_squares":#{stats.sum_of_squares},"total_call_time":#{stats.total_call_time},"max_call_time":#{stats.max_call_time}}})
end
to_s() click to toggle source
# File lib/new_relic/metric_data.rb, line 54
def to_s
  "#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
end

Private Instance Methods

stats_collector_array(stat_key) click to toggle source
# File lib/new_relic/metric_data.rb, line 60
def stats_collector_array(stat_key)
  [[:call_count, Integer], [:total_call_time, Float],
    [:total_exclusive_time, Float], [:min_call_time, Float],
    [:max_call_time, Float], [:sum_of_squares, Float]].map do |attr_types|
    if attr_types[1].eql?(Integer)
      int(stats.send(attr_types[0]), stat_key)
    elsif attr_types[1].eql?(Float)
      float(stats.send(attr_types[0]), stat_key)
    end
  end
end