Class: NewRelic::MetricSpec
- Inherits:
-
Object
- Object
- NewRelic::MetricSpec
- Defined in:
- lib/new_relic/metric_spec.rb
Overview
this struct uniquely defines a metric, optionally inside the call scope of another metric
Constant Summary collapse
- MAX_LENGTH =
the maximum length of a metric name or metric scope
255
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #==(o) ⇒ Object
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(metric_name = '', metric_scope = '') ⇒ MetricSpec
constructor
Need a “zero-arg” constructor so it can be instantiated from java (using jruby) for sending responses to ruby agents from the java collector.
- #inspect ⇒ Object
-
#sub(pattern, replacement, apply_to_scope = true) ⇒ Object
return a new metric spec if the given regex matches the name or scope.
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
-
#truncate! ⇒ Object
truncates the name and scope to the MAX_LENGTH.
Constructor Details
#initialize(metric_name = '', metric_scope = '') ⇒ MetricSpec
Need a “zero-arg” constructor so it can be instantiated from java (using jruby) for sending responses to ruby agents from the java collector.
12 13 14 15 |
# File 'lib/new_relic/metric_spec.rb', line 12 def initialize(metric_name = '', metric_scope = '') self.name = (metric_name || '') && metric_name[0...MAX_LENGTH] self.scope = metric_scope && metric_scope[0...MAX_LENGTH] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/new_relic/metric_spec.rb', line 4 def name @name end |
#scope ⇒ Object
Returns the value of attribute scope.
5 6 7 |
# File 'lib/new_relic/metric_spec.rb', line 5 def scope @scope end |
Instance Method Details
#<=>(o) ⇒ Object
70 71 72 73 74 |
# File 'lib/new_relic/metric_spec.rb', line 70 def <=>(o) namecmp = self.name <=> o.name return namecmp if namecmp != 0 return (self.scope || '') <=> (o.scope || '') end |
#==(o) ⇒ Object
23 24 25 |
# File 'lib/new_relic/metric_spec.rb', line 23 def ==(o) self.eql?(o) end |
#eql?(o) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/new_relic/metric_spec.rb', line 27 def eql? o self.class == o.class && name.eql?(o.name) && # coerce scope to a string and compare scope.to_s == o.scope.to_s end |
#hash ⇒ Object
34 35 36 37 38 |
# File 'lib/new_relic/metric_spec.rb', line 34 def hash h = name.hash h ^= scope.hash unless scope.nil? h end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/new_relic/metric_spec.rb', line 61 def inspect "#<NewRelic::MetricSpec '#{name}':'#{scope}'>" end |
#sub(pattern, replacement, apply_to_scope = true) ⇒ Object
return a new metric spec if the given regex matches the name or scope.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/new_relic/metric_spec.rb', line 41 def sub(pattern, replacement, apply_to_scope = true) NewRelic::Control.instance.log.warn("The sub method on metric specs is deprecated") rescue nil return nil if name !~ pattern && (!apply_to_scope || scope.nil? || scope !~ pattern) new_name = name.sub(pattern, replacement)[0...MAX_LENGTH] if apply_to_scope new_scope = (scope && scope.sub(pattern, replacement)[0...MAX_LENGTH]) else new_scope = scope end self.class.new new_name, new_scope end |
#to_json(*a) ⇒ Object
65 66 67 68 |
# File 'lib/new_relic/metric_spec.rb', line 65 def to_json(*a) {'name' => name, 'scope' => scope}.to_json(*a) end |
#to_s ⇒ Object
56 57 58 59 |
# File 'lib/new_relic/metric_spec.rb', line 56 def to_s return name if scope.empty? "#{name}:#{scope}" end |
#truncate! ⇒ Object
truncates the name and scope to the MAX_LENGTH
18 19 20 21 |
# File 'lib/new_relic/metric_spec.rb', line 18 def truncate! self.name = name[0...MAX_LENGTH] if name && name.size > MAX_LENGTH self.scope = scope[0...MAX_LENGTH] if scope && scope.size > MAX_LENGTH end |