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.



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

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

Returns the value of attribute metric_id.



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

def metric_id
  @metric_id
end

#metric_specObject

Returns the value of attribute metric_spec.



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

def metric_spec
  @metric_spec
end

#statsObject

Returns the value of attribute stats.



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

def stats
  @stats
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/new_relic/metric_data.rb', line 13

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

#hashObject



28
29
30
# File 'lib/new_relic/metric_data.rb', line 28

def hash
  metric_spec.hash ^ stats.hash
end

#original_specObject



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

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



33
34
35
# File 'lib/new_relic/metric_data.rb', line 33

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



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

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