Class: NewRelic::MetricData

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Coerce

#float, #int, #log_failure, #string

Constructor Details

#initialize(metric_spec, stats, metric_id) ⇒ MetricData

Returns a new instance of MetricData.



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

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.



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

def metric_id
  @metric_id
end

#metric_specObject

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



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

def metric_spec
  @metric_spec
end

#statsObject

the actual statistics object



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

def stats
  @stats
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  metric_spec.hash ^ stats.hash
end

#inspectObject



50
51
52
# File 'lib/new_relic/metric_data.rb', line 50

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

#original_specObject



22
23
24
# File 'lib/new_relic/metric_data.rb', line 22

def original_spec
  @original_spec || @metric_spec
end

#to_collector_array(encoder = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/new_relic/metric_data.rb', line 56

def to_collector_array(encoder=nil)
  stat_key = metric_id || { 'name' => metric_spec.name, 'scope' => metric_spec.scope }
  [ stat_key,
    [
      int(stats.call_count, stat_key),
      float(stats.total_call_time, stat_key),
      float(stats.total_exclusive_time, stat_key),
      float(stats.min_call_time, stat_key),
      float(stats.max_call_time, stat_key),
      float(stats.sum_of_squares, stat_key)
    ]
  ]
end

#to_json(*a) ⇒ Object

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



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

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



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

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