Class: NewRelic::MetricData
- Inherits:
-
Object
- Object
- NewRelic::MetricData
- Includes:
- Coerce
- Defined in:
- lib/new_relic/metric_data.rb
Instance Attribute Summary collapse
-
#metric_id ⇒ Object
nil or a cached integer ID for the metric from the collector.
-
#metric_spec ⇒ Object
nil, or a NewRelic::MetricSpec object if we have no cached ID.
-
#stats ⇒ Object
the actual statistics object.
Instance Method Summary collapse
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(metric_spec, stats, metric_id) ⇒ MetricData
constructor
A new instance of MetricData.
- #inspect ⇒ Object
- #original_spec ⇒ Object
- #to_collector_array(encoder = nil) ⇒ Object
-
#to_json(*a) ⇒ Object
Serialize with all attributes, but if the metric id is not nil, then don’t send the metric spec.
- #to_s ⇒ Object
Methods included from Coerce
#float, #int, #log_failure, #string
Constructor Details
#initialize(metric_spec, stats, metric_id) ⇒ MetricData
Returns a new instance of MetricData.
16 17 18 19 20 |
# File 'lib/new_relic/metric_data.rb', line 16 def initialize(metric_spec, stats, metric_id) @metric_spec = metric_spec self.stats = stats self.metric_id = metric_id end |
Instance Attribute Details
#metric_id ⇒ Object
nil or a cached integer ID for the metric from the collector.
12 13 14 |
# File 'lib/new_relic/metric_data.rb', line 12 def metric_id @metric_id end |
#metric_spec ⇒ Object
nil, or a NewRelic::MetricSpec object if we have no cached ID
10 11 12 |
# File 'lib/new_relic/metric_data.rb', line 10 def metric_spec @metric_spec end |
#stats ⇒ Object
the actual statistics object
14 15 16 |
# File 'lib/new_relic/metric_data.rb', line 14 def stats @stats end |
Instance Method Details
#eql?(o) ⇒ Boolean
22 23 24 |
# File 'lib/new_relic/metric_data.rb', line 22 def eql?(o) (metric_spec.eql? o.metric_spec) && (stats.eql? o.stats) end |
#hash ⇒ Object
37 38 39 |
# File 'lib/new_relic/metric_data.rb', line 37 def hash metric_spec.hash ^ stats.hash end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/new_relic/metric_data.rb', line 54 def inspect "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>" end |
#original_spec ⇒ Object
26 27 28 |
# File 'lib/new_relic/metric_data.rb', line 26 def original_spec @original_spec || @metric_spec end |
#to_collector_array(encoder = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/new_relic/metric_data.rb', line 60 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
42 43 44 |
# File 'lib/new_relic/metric_data.rb', line 42 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_s ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/new_relic/metric_data.rb', line 46 def to_s if metric_spec "#{metric_spec.name}(#{metric_spec.scope}): #{stats}" else "#{metric_id}: #{stats}" end end |