Class: NewRelic::MetricParser

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

Overview

Metric parsing logic mixin. Given a metric name (attribute called “name”), provide a set of accessors that enable inspection of the metric. A metric has 2 or more segments, each separated by the ‘/’ character. The metric’s category is specified by its first segment. Following are the set of categories currently supported by NewRelic’s default metric set:

  • Controller

  • ActiveRecord

  • Rails

  • WebService

  • View

  • Database

  • Custom

Based on the category of the metric, specific parsing logic is defined in the source files countained in the “metric_parsers” sub directory local to this file.

Defined Under Namespace

Classes: ActionMailer, ActiveMerchant, ActiveRecord, Controller, ControllerCPU, Errors, External, MemCache, OtherTransaction, View, WebFrontend, WebService

Constant Summary collapse

SEPARATOR =
'/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ MetricParser

returns a hash of params for url_for(), giving you a drilldown URL to an RPM page for this metric define in subclasses - TB 2009-12-18 def drilldown_url(metric_id); end



119
120
121
# File 'lib/new_relic/metric_parser.rb', line 119

def initialize(name)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



41
42
43
44
# File 'lib/new_relic/metric_parser.rb', line 41

def method_missing(method_name, *args)
  return false if method_name.to_s =~ /^is_.*\?/
  super
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.for_metric_named(s) ⇒ Object

return a string that is parsable via the Metric parser APIs



28
29
30
31
32
33
34
35
# File 'lib/new_relic/metric_parser.rb', line 28

def self.for_metric_named(s)
  category = (s =~ /^([^\/]*)/) && $1
  parser_class = self
  if category
    parser_class = NewRelic::MetricParser.const_get(category) if (NewRelic::MetricParser.const_defined?(category) rescue nil)
  end
  parser_class.new s
end

.parse(s) ⇒ Object



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

def self.parse(s)
  for_metric_named(s)
end

Instance Method Details

#apdex_metric_pathObject



69
70
71
# File 'lib/new_relic/metric_parser.rb', line 69

def apdex_metric_path
  "Apdex/#{segments[1..-1].join('/')}"
end

#base_metric_nameObject

Return the name of another metric if the current metric is really add-on data for another metric.



80
81
82
# File 'lib/new_relic/metric_parser.rb', line 80

def base_metric_name
  nil
end

#call_rate_suffixObject

This is the suffix used for call rate or throughput. By default, it’s cpm but things like controller actions will override to use something like ‘rpm’ for requests per minute



107
108
109
# File 'lib/new_relic/metric_parser.rb', line 107

def call_rate_suffix
'cpm'
end

#categoryObject



84
85
86
# File 'lib/new_relic/metric_parser.rb', line 84

def category
  segments[0]
end

#developer_nameObject



61
62
63
# File 'lib/new_relic/metric_parser.rb', line 61

def developer_name
  short_name
end

#last_segmentObject



102
# File 'lib/new_relic/metric_parser.rb', line 102

def last_segment; segments.last; end

#legend_nameObject

A short name for legends in the graphs



74
75
76
# File 'lib/new_relic/metric_parser.rb', line 74

def legend_name
  short_name
end

#pie_chart_labelObject



57
58
59
# File 'lib/new_relic/metric_parser.rb', line 57

def pie_chart_label
  developer_name
end

#segment_0Object

– These accessors are used to allow chart to use a specific segment in the metric name for label construction as a zero-arg accessor ++



97
# File 'lib/new_relic/metric_parser.rb', line 97

def segment_0; segments[0]; end

#segment_1Object



98
# File 'lib/new_relic/metric_parser.rb', line 98

def segment_1; segments[1]; end

#segment_2Object



99
# File 'lib/new_relic/metric_parser.rb', line 99

def segment_2; segments[2]; end

#segment_3Object



100
# File 'lib/new_relic/metric_parser.rb', line 100

def segment_3; segments[3]; end

#segment_4Object



101
# File 'lib/new_relic/metric_parser.rb', line 101

def segment_4; segments[4]; end

#segmentsObject



88
89
90
91
# File 'lib/new_relic/metric_parser.rb', line 88

def segments
  return [] if !name
  @segments ||= name.split(SEPARATOR).freeze
end

#short_nameObject

The short name for the metric is defined as all of the segments of the metric name except for its first (its domain).



47
48
49
50
51
52
53
54
55
# File 'lib/new_relic/metric_parser.rb', line 47

def short_name
  if segments.empty?
    ''
  elsif segments.length == 1
    segments[0]
  else
    segments[1..-1].join(SEPARATOR)
  end
end

#tooltip_nameObject



65
66
67
# File 'lib/new_relic/metric_parser.rb', line 65

def tooltip_name
  short_name
end

#urlObject



111
112
113
# File 'lib/new_relic/metric_parser.rb', line 111

def url
''
end