Class: NewRelic::MetricParser

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/metric_parser.rb,
lib/new_relic/metric_parser/apdex.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, Apdex, 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



126
127
128
# File 'lib/new_relic/metric_parser.rb', line 126

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
  %Q[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



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

def call_rate_suffix
'cpm'
end

#categoryObject

Category is a UI description of the general category of metrics for this metric.



86
87
88
# File 'lib/new_relic/metric_parser.rb', line 86

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

#is_controller?Boolean

These would be reflected properly by method missing; consider this an optimization

Returns:

  • (Boolean)


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

def is_controller?; false; end

#is_transaction?Boolean

Returns:

  • (Boolean)


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

def is_transaction?; false; end

#last_segmentObject



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

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 ++



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

def segment_0; segments[0]; end

#segment_1Object



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

def segment_1; segments[1]; end

#segment_2Object



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

def segment_2; segments[2]; end

#segment_3Object



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

def segment_3; segments[3]; end

#segment_4Object



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

def segment_4; segments[4]; end

#segment_5Object



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

def segment_5; segments[5]; end

#segmentsObject



90
91
92
93
# File 'lib/new_relic/metric_parser.rb', line 90

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

#summary_metricsObject

Return the list of dispatcher metrics that correspond to this metric. That is, the summary metrics which should also be recorded when this metric is recorded.



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

def summary_metrics
  []
end

#tooltip_nameObject



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

def tooltip_name
  short_name
end

#urlObject



114
115
116
# File 'lib/new_relic/metric_parser.rb', line 114

def url
''
end