Class: NewRelic::MetricData

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/metric_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric_spec, stats, metric_id) ⇒ MetricData

Returns a new instance of MetricData.



10
11
12
13
14
# File 'lib/new_relic/metric_data.rb', line 10

def initialize(metric_spec, stats, metric_id)
  @metric_spec = metric_spec
  self.stats = stats
  self.metric_id = metric_id
end

Instance Attribute Details

#metric_idObject

nil or a cached integer ID for the metric from the collector.



6
7
8
# File 'lib/new_relic/metric_data.rb', line 6

def metric_id
  @metric_id
end

#metric_specObject

nil, or a NewRelic::MetricSpec object if we have no cached ID



4
5
6
# File 'lib/new_relic/metric_data.rb', line 4

def metric_spec
  @metric_spec
end

#statsObject

the actual statistics object



8
9
10
# File 'lib/new_relic/metric_data.rb', line 8

def stats
  @stats
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/new_relic/metric_data.rb', line 16

def eql?(o)
 (metric_spec.eql? o.metric_spec) && (stats.eql? o.stats)
end

#hashObject



31
32
33
# File 'lib/new_relic/metric_data.rb', line 31

def hash
  metric_spec.hash ^ stats.hash
end

#inspectObject



47
48
49
# File 'lib/new_relic/metric_data.rb', line 47

def inspect
  "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>"
end

#original_specObject



20
21
22
# File 'lib/new_relic/metric_data.rb', line 20

def original_spec
  @original_spec || @metric_spec
end

#to_json(*a) ⇒ Object

Serialize with all attributes, but if the metric id is not nil, then don’t send the metric spec



36
37
38
# File 'lib/new_relic/metric_data.rb', line 36

def to_json(*a)
   %Q[{"metric_spec":#{metric_id ? 'null' : 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}},"metric_id":#{metric_id ? metric_id : 'null'}}]
end

#to_sObject



40
41
42
43
44
45
46
# File 'lib/new_relic/metric_data.rb', line 40

def to_s
  if metric_spec
    "#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
  else
    "#{metric_id}: #{stats}"
  end
end