newrelic_rpm 2.8.11 → 2.9.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (137) hide show
  1. data/CHANGELOG +267 -0
  2. data/LICENSE +1 -1
  3. data/Manifest +142 -0
  4. data/README.md +138 -0
  5. data/Rakefile +10 -28
  6. data/bin/mongrel_rpm +33 -0
  7. data/cert/cacert.pem +34 -0
  8. data/init.rb +38 -0
  9. data/lib/new_relic/agent/agent.rb +160 -347
  10. data/lib/new_relic/agent/collection_helper.rb +13 -24
  11. data/lib/new_relic/agent/error_collector.rb +29 -15
  12. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
  14. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
  15. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
  16. data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
  17. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
  18. data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
  19. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
  20. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
  21. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
  22. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
  23. data/lib/new_relic/agent/method_tracer.rb +159 -135
  24. data/lib/new_relic/agent/patch_const_missing.rb +46 -26
  25. data/lib/new_relic/agent/sampler.rb +12 -0
  26. data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
  27. data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
  28. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  29. data/lib/new_relic/agent/shim_agent.rb +11 -0
  30. data/lib/new_relic/agent/stats_engine.rb +85 -46
  31. data/lib/new_relic/agent/transaction_sampler.rb +63 -38
  32. data/lib/new_relic/agent/worker_loop.rb +8 -18
  33. data/lib/new_relic/agent.rb +200 -25
  34. data/lib/new_relic/commands/deployments.rb +9 -9
  35. data/lib/new_relic/control/merb.rb +22 -0
  36. data/lib/new_relic/control/rails.rb +141 -0
  37. data/lib/new_relic/{config → control}/ruby.rb +13 -2
  38. data/lib/new_relic/control.rb +424 -0
  39. data/lib/new_relic/local_environment.rb +201 -79
  40. data/lib/new_relic/metric_data.rb +7 -0
  41. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  42. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  43. data/lib/new_relic/metric_parser/active_record.rb +11 -0
  44. data/lib/new_relic/metric_parser/controller.rb +51 -0
  45. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  46. data/lib/new_relic/metric_parser/database.rb +23 -0
  47. data/lib/new_relic/metric_parser/errors.rb +6 -0
  48. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  49. data/lib/new_relic/metric_parser/view.rb +61 -0
  50. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  51. data/lib/new_relic/metric_parser.rb +107 -0
  52. data/lib/new_relic/metric_spec.rb +5 -0
  53. data/lib/new_relic/noticed_error.rb +5 -1
  54. data/lib/new_relic/rack/metric_app.rb +57 -0
  55. data/lib/new_relic/rack/newrelic.ru +25 -0
  56. data/lib/new_relic/rack/newrelic.yml +25 -0
  57. data/lib/new_relic/rack.rb +5 -0
  58. data/lib/new_relic/recipes.rb +10 -3
  59. data/lib/new_relic/stats.rb +130 -144
  60. data/lib/new_relic/transaction_analysis.rb +7 -8
  61. data/lib/new_relic/transaction_sample.rb +86 -10
  62. data/lib/new_relic/version.rb +41 -160
  63. data/lib/new_relic_api.rb +7 -6
  64. data/lib/newrelic_rpm.rb +30 -17
  65. data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
  66. data/newrelic.yml +115 -62
  67. data/newrelic_rpm.gemspec +36 -0
  68. data/test/active_record_fixtures.rb +55 -0
  69. data/test/config/newrelic.yml +21 -3
  70. data/test/config/{test_config.rb → test_control.rb} +14 -10
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
  72. data/test/new_relic/agent/agent_test.rb +104 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +18 -1
  74. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  75. data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
  76. data/test/new_relic/agent/controller_test.rb +107 -0
  77. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
  78. data/test/new_relic/agent/error_collector_test.rb +155 -0
  79. data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
  80. data/test/new_relic/agent/metric_data_test.rb +56 -0
  81. data/test/new_relic/agent/stats_engine_test.rb +266 -0
  82. data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
  83. data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
  84. data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
  85. data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
  86. data/test/new_relic/control_test.rb +97 -0
  87. data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
  88. data/test/new_relic/environment_test.rb +75 -0
  89. data/test/new_relic/metric_parser_test.rb +142 -0
  90. data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
  91. data/test/new_relic/samplers_test.rb +71 -0
  92. data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
  93. data/test/new_relic/stats_test.rb +291 -0
  94. data/test/new_relic/version_number_test.rb +46 -0
  95. data/test/test_helper.rb +7 -30
  96. data/test/ui/newrelic_controller_test.rb +14 -0
  97. data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
  98. data/ui/controllers/newrelic_controller.rb +17 -3
  99. data/ui/helpers/newrelic_helper.rb +44 -15
  100. data/ui/views/layouts/newrelic_default.rhtml +7 -8
  101. data/ui/views/newrelic/_sample.rhtml +5 -2
  102. data/ui/views/newrelic/_segment.rhtml +1 -1
  103. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  104. data/ui/views/newrelic/_segment_row.rhtml +4 -4
  105. data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
  106. data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
  107. data/ui/views/newrelic/explain_sql.rhtml +2 -5
  108. data/ui/views/newrelic/images/file_icon.png +0 -0
  109. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  110. data/ui/views/newrelic/index.rhtml +21 -13
  111. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  112. data/ui/views/newrelic/show_sample.rhtml +18 -3
  113. data/ui/views/newrelic/stylesheets/style.css +39 -0
  114. data/ui/views/newrelic/threads.rhtml +52 -0
  115. metadata +192 -70
  116. data/README +0 -136
  117. data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
  118. data/lib/new_relic/agent/samplers/cpu.rb +0 -29
  119. data/lib/new_relic/agent/samplers/memory.rb +0 -53
  120. data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
  121. data/lib/new_relic/agent/synchronize.rb +0 -40
  122. data/lib/new_relic/config/merb.rb +0 -35
  123. data/lib/new_relic/config/rails.rb +0 -114
  124. data/lib/new_relic/config.rb +0 -279
  125. data/lib/new_relic/shim_agent.rb +0 -96
  126. data/test/new_relic/agent/model_fixture.rb +0 -15
  127. data/test/new_relic/agent/tc_active_record.rb +0 -90
  128. data/test/new_relic/agent/tc_agent.rb +0 -148
  129. data/test/new_relic/agent/tc_controller.rb +0 -77
  130. data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
  131. data/test/new_relic/agent/tc_error_collector.rb +0 -127
  132. data/test/new_relic/agent/tc_stats_engine.rb +0 -218
  133. data/test/new_relic/agent/tc_synchronize.rb +0 -37
  134. data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
  135. data/test/new_relic/tc_config.rb +0 -36
  136. data/test/new_relic/tc_environment.rb +0 -94
  137. data/test/new_relic/tc_stats.rb +0 -141
@@ -1,140 +1,262 @@
1
- # An instance of LocalEnvironment will provide the environment name
2
- # and locally unique identifier for this agent's host.
3
- # If the environment can't be determined, it will be set to
4
- # :unknown and identifier will have nil
1
+ require 'set'
2
+
5
3
  module NewRelic
4
+ # An instance of LocalEnvironment is responsible for determining
5
+ # three things:
6
+ #
7
+ # * Framework - :rails, :merb, :ruby, :test
8
+ # * Dispatcher - A supported dispatcher, or nil (:mongrel, :thin, :passenger, :webrick, etc)
9
+ # * Dispatcher Instance ID, which distinguishes agents on a single host from each other
10
+ #
11
+ # If the environment can't be determined, it will be set to
12
+ # nil and dispatcher_instance_id will have nil.
13
+ #
14
+ # NewRelic::LocalEnvironment should be accessed through NewRelic::Control#env (via the NewRelic::Control singleton).
6
15
  class LocalEnvironment
16
+
17
+ attr_accessor :dispatcher # mongrel, thin, webrick, or possibly nil
18
+ attr_accessor :dispatcher_instance_id # used to distinguish instances of a dispatcher from each other, may be nil
19
+ attr_accessor :framework # rails, merb, :ruby, test
20
+ attr_reader :mongrel # The mongrel instance, if there is one, captured as a convenience
21
+ attr_reader :processors # The number of cpus, if detected, or nil
22
+ alias environment dispatcher
7
23
 
8
- attr_reader :environment, :identifier
9
-
10
- # determine the environment we are running in (one of :webrick,
11
- # :mongrel, :thin, or :unknown) and if the process is listening
12
- # on a port, use the port # that we are listening on.
13
24
  def initialize
14
- # Note: log won't be available yet.
15
- @identifier = nil
16
- @environment = :unknown
17
- environments = %w[merb jruby webrick thin mongrel litespeed passenger fastcgi daemon]
18
- while environments.any? && @identifier.nil?
19
- send 'check_for_'+(environments.shift)
25
+ discover_framework
26
+ discover_dispatcher
27
+ @dispatcher = nil if @dispatcher == :none
28
+ @gems = Set.new
29
+ @plugins = Set.new
30
+ @config = Hash.new
31
+ end
32
+
33
+ # Add the given key/value pair to the app environment
34
+ # settings. Must pass either a value or a block. Block
35
+ # is called to get the value and any raised errors are
36
+ # silently ignored.
37
+ def append_environment_value name, value = nil
38
+ value = yield if block_given?
39
+ @config[name] = value if value
40
+ rescue Exception
41
+ # puts "#{e}\n #{e.backtrace.join("\n ")}"
42
+ raise if @framework == :test
43
+ end
44
+
45
+ def append_gem_list
46
+ @gems += yield
47
+ rescue Exception => e
48
+ # puts "#{e}\n #{e.backtrace.join("\n ")}"
49
+ raise if @framework == :test
50
+ end
51
+
52
+ def append_plugin_list
53
+ @plugins += yield
54
+ rescue Exception
55
+ # puts "#{e}\n #{e.backtrace.join("\n ")}"
56
+ raise if @framework == :test
57
+ end
58
+
59
+ def dispatcher_instance_id
60
+ if @dispatcher_instance_id.nil?
61
+ if @dispatcher.nil?
62
+ @dispatcher_instance_id = File.basename($0).split(".").first
63
+ end
20
64
  end
65
+ @dispatcher_instance_id
21
66
  end
22
- def to_s
23
- "LocalEnvironment[#{environment}:#{identifier}]"
67
+
68
+ # Collect base statistics about the environment and record them for
69
+ # comparison and change detection.
70
+ def gather_environment_info
71
+ append_environment_value 'Framework', @framework.to_s
72
+ append_environment_value 'Dispatcher', @dispatcher.to_s if @dispatcher
73
+ append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
74
+ append_environment_value('Application root') { File.expand_path(NewRelic::Control.instance.root) }
75
+ append_environment_value('Ruby version'){ RUBY_VERSION }
76
+ append_environment_value('Ruby platform') { RUBY_PLATFORM }
77
+ append_environment_value('Ruby patchlevel') { RUBY_PATCHLEVEL }
78
+ append_environment_value('OS version') { `uname -v` }
79
+ append_environment_value('OS') { `uname -s` } ||
80
+ append_environment_value('OS') { ENV['OS'] }
81
+ append_environment_value('Arch') { `uname -p` } ||
82
+ append_environment_value('Arch') { ENV['PROCESSOR_ARCHITECTURE'] }
83
+ # See what the number of cpus is, works only on linux.
84
+ @processors = append_environment_value('Processors') do
85
+ processors = 0
86
+ File.read('/proc/cpuinfo').each_line do | line |
87
+ processors += 1 if line =~ /^processor\s*:/
88
+ end
89
+ raise unless processors > 0
90
+ processors
91
+ end if File.readable? '/proc/cpuinfo'
92
+ # The current Rails environment (development, test, or production).
93
+ append_environment_value('Environment') { NewRelic::Control.instance.env }
94
+ # Look for a capistrano file indicating the current revision:
95
+ rev_file = File.join(NewRelic::Control.instance.root, "REVISION")
96
+ if File.readable?(rev_file) && File.size(rev_file) < 64
97
+ append_environment_value('Revision') do
98
+ File.open(rev_file) { | file | file.readline.strip }
99
+ end
100
+ end
101
+ # The name of the database adapter for the current environment.
102
+ if defined? ActiveRecord
103
+ append_environment_value 'Database adapter' do
104
+ ActiveRecord::Base.configurations[RAILS_ENV]['adapter']
105
+ end
106
+ append_environment_value 'Database schema version' do
107
+ ActiveRecord::Migrator.current_version
108
+ end
109
+ end
110
+ if defined? DataMapper
111
+ append_environment_value 'DataMapper version' do
112
+ require 'dm-core/version'
113
+ DataMapper::VERSION
114
+ end
115
+ end
24
116
  end
25
- def check_for_fastcgi
26
- return unless defined? FCGI
27
- @environment = :fastcgi
28
- @identifier = 'fastcgi'
117
+ # Take a snapshot of the environment information for this application
118
+ # Returns an associative array
119
+ def snapshot
120
+ i = @config.to_a
121
+ i << [ 'Plugin List', @plugins.to_a] if not @plugins.empty?
122
+ i << [ 'Gems', @gems.to_a] if not @gems.empty?
123
+ i
29
124
  end
30
- def check_for_merb
31
- if config.app == :merb
32
- @identifier = 'merb'
125
+
126
+ def mongrel
127
+ return @mongrel if @mongrel || ! defined? Mongrel::HttpServer
128
+ ObjectSpace.each_object(Mongrel::HttpServer) do |mongrel|
129
+ @mongrel = mongrel
130
+ end unless defined?(JRuby) && !JRuby.runtime.is_object_space_enabled
131
+ @mongrel
132
+ end
133
+
134
+ private
135
+
136
+ # Although you can override the framework with NEWRELIC_DISPATCHER this
137
+ # is not advisable since it implies certain api's being available.
138
+ def discover_dispatcher
139
+ @dispatcher = ENV['NEWRELIC_DISPATCHER'] && ENV['NEWRELIC_DISPATCHER'].to_sym
140
+ dispatchers = %w[webrick thin mongrel glassfish litespeed passenger fastcgi]
141
+ while dispatchers.any? && @dispatcher.nil?
142
+ send 'check_for_'+(dispatchers.shift)
33
143
  end
34
144
  end
145
+
146
+ def discover_framework
147
+ # Although you can override the framework with NEWRELIC_FRAMEWORK this
148
+ # is not advisable since it implies certain api's being available.
149
+ @framework = case
150
+ when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
151
+ when defined? NewRelic::TEST then :test
152
+ when defined? Merb::Plugins then :merb
153
+ when defined? Rails then :rails
154
+ else :ruby
155
+ end
156
+ end
157
+
158
+ def check_for_glassfish
159
+ return unless defined?(Java) &&
160
+ (((com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
161
+ defined?(com::sun::grizzly::jruby::rack::DefaultRackApplicationFactory)) ||
162
+ ((org.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
163
+ defined?(org::jruby::rack::DefaultRackApplicationFactory)))
164
+ @dispatcher = :glassfish
165
+ end
166
+
35
167
  def check_for_webrick
36
- # Some indication this is causing problems. To be fixed in 2.9.0
37
- return
38
- # This will not succeed on rails 2.2 and later
39
- if defined?(WEBrick) && defined?(OPTIONS) && ::OPTIONS.respond_to?(:fetch)
40
- # OPTIONS is set by script/server
41
- @identifier = default_port unless @identifier
42
- @identifier = OPTIONS.fetch(:port)
168
+ return unless defined?(WEBrick::VERSION)
169
+ @dispatcher = :webrick
170
+ if defined?(OPTIONS) && OPTIONS.respond_to?(:fetch)
171
+ # OPTIONS is set by script/server
172
+ @dispatcher_instance_id = OPTIONS.fetch(:port)
43
173
  end
174
+ @dispatcher_instance_id = default_port unless @dispatcher_instance_id
44
175
  end
176
+
177
+ def check_for_fastcgi
178
+ return unless defined? FCGI
179
+ @dispatcher = :fastcgi
180
+ end
181
+
45
182
  # this case covers starting by mongrel_rails
46
183
  def check_for_mongrel
47
184
  return unless defined?(Mongrel::HttpServer)
48
- @environment = :mongrel
185
+ @dispatcher = :mongrel
49
186
 
50
187
  # Get the port from the server if it's started
51
- ObjectSpace.each_object(Mongrel::HttpServer) do |mongrel|
52
- next if not mongrel.respond_to? :port
53
- @identifier = mongrel.port.to_s
188
+
189
+ if mongrel && mongrel.respond_to?(:port)
190
+ @dispatcher_instance_id = mongrel.port.to_s
54
191
  end
55
192
 
56
193
  # Get the port from the configurator if one was created
57
- if @identifier.nil? && defined?(Mongrel::Configurator)
194
+ if @dispatcher_instance_id.nil? && defined?(Mongrel::Configurator)
58
195
  ObjectSpace.each_object(Mongrel::Configurator) do |mongrel|
59
- @identifier = mongrel.defaults[:port] && mongrel.defaults[:port].to_s
60
- end
196
+ @dispatcher_instance_id = mongrel.defaults[:port] && mongrel.defaults[:port].to_s
197
+ end unless defined?(JRuby) && !JRuby.runtime.is_object_space_enabled
61
198
  end
199
+ @mongrel
62
200
 
63
201
  # Still can't find the port. Let's look at ARGV to fall back
64
- @identifier = default_port if @identifier.nil?
202
+ @dispatcher_instance_id = default_port if @dispatcher_instance_id.nil?
65
203
  end
66
- def check_for_thin
204
+
205
+ def check_for_thin
67
206
  if defined? Thin::Server
68
207
  # This case covers the thin web dispatcher
69
208
  # Same issue as above- we assume only one instance per process
70
- ObjectSpace.each_object(Thin::Server) do |thin_server|
71
- @environment = :thin
72
- backend = thin_server.backend
209
+ ObjectSpace.each_object(Thin::Server) do |thin_dispatcher|
210
+ @dispatcher = :thin
211
+ backend = thin_dispatcher.backend
73
212
  # We need a way to uniquely identify and distinguish agents. The port
74
213
  # works for this. When using sockets, use the socket file name.
75
214
  if backend.respond_to? :port
76
- @identifier = backend.port
215
+ @dispatcher_instance_id = backend.port
77
216
  elsif backend.respond_to? :socket
78
- @identifier = backend.socket
217
+ @dispatcher_instance_id = backend.socket
79
218
  else
80
219
  raise "Unknown thin backend: #{backend}"
81
220
  end
82
221
  end # each thin instance
83
222
  end
84
- if defined?(Thin::VERSION) && !@identifier
85
- @environment = :thin
86
- @identifier = default_port
87
- end
88
- end
89
-
90
- def check_for_jruby
91
- if RUBY_PLATFORM =~ /java/
92
- # Check for JRuby environment. Not sure how this works in different appservers
93
- require 'java'
94
- require 'jruby'
95
- @environment = :jruby
96
- @identifier = 'jruby'
97
- @identifier += ":#{config['app_name']}" if config['app_name']
223
+ if defined?(Thin::VERSION) && !@dispatcher
224
+ @dispatcher = :thin
225
+ @dispatcher_instance_id = default_port
98
226
  end
99
227
  end
100
228
 
101
229
  def check_for_litespeed
102
230
  if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/
103
- @environment = :litespeed
104
- @identifier = 'litespeed'
105
- @identifier += ":#{config['app_name']}" if config['app_name']
231
+ @dispatcher = :litespeed
106
232
  end
107
233
  end
108
234
 
109
235
  def check_for_passenger
110
236
  if defined?(Passenger::AbstractServer) || defined?(IN_PHUSION_PASSENGER)
111
- @environment = :passenger
112
- @identifier = 'passenger'
113
- @identifier += ":#{config['app_name']}" if config['app_name']
114
- end
115
- end
116
-
117
- def check_for_daemon
118
- if config['monitor_daemons']
119
- @environment = :daemon
120
- # return the base part of the file name
121
- @identifier = File.basename($0).split(".").first
237
+ @dispatcher = :passenger
122
238
  end
123
239
  end
124
- private
125
- def config
126
- NewRelic::Config.instance
127
- end
128
-
240
+
129
241
  def default_port
130
242
  require 'optparse'
131
243
  # If nothing else is found, use the 3000 default
132
244
  default_port = 3000
133
245
  OptionParser.new do |opts|
134
- opts.on("-p", "--port=port", String) { | default_port | }
246
+ opts.on("-p", "--port=port", String) { | p | default_port = p }
135
247
  opts.parse(ARGV.clone) rescue nil
136
248
  end
137
249
  default_port
138
250
  end
251
+
252
+ public
253
+ def to_s
254
+ s = "LocalEnvironment["
255
+ s << @framework.to_s
256
+ s << ";dispatcher=#{@dispatcher}" if @dispatcher
257
+ s << ";instance=#{@dispatcher_instance_id}" if @dispatcher_instance_id
258
+ s << "]"
259
+ end
260
+
139
261
  end
140
262
  end
@@ -18,6 +18,13 @@ module NewRelic
18
18
  metric_spec.hash + stats.hash
19
19
  end
20
20
 
21
+ def to_json(*a)
22
+ {'metric_spec' => metric_spec,
23
+ 'stats' => stats,
24
+ 'metric_id' => metric_id
25
+ }.to_json(*a)
26
+ end
27
+
21
28
  def to_s
22
29
  "#{metric_spec.name}(#{metric_spec.scope}): #{stats}" if metric_spec
23
30
  "#{metric_id}: #{stats}" if metric_spec.nil?
@@ -0,0 +1,9 @@
1
+ class NewRelic::MetricParser::ActionMailer < NewRelic::MetricParser
2
+
3
+ def is_action_mailer?; true; end
4
+
5
+ def short_name
6
+ "ActionMailer - #{segments[1]}"
7
+ end
8
+
9
+ end
@@ -0,0 +1,26 @@
1
+ class NewRelic::MetricParser::ActiveMerchant < NewRelic::MetricParser
2
+
3
+ def is_active_merchant?; true; end
4
+
5
+ def is_active_merchant_gateway?
6
+ segments[1] == 'gateway'
7
+ end
8
+
9
+ def is_active_merchant_operation?
10
+ segments[1] == 'operation'
11
+ end
12
+
13
+ def gateway_name
14
+ # ends in "Gateway" - trim that off
15
+ segments[2][0..-8].titleize
16
+ end
17
+
18
+ def operation_name
19
+ segments[2]
20
+ end
21
+
22
+ def short_name
23
+ segments[2]
24
+ end
25
+
26
+ end
@@ -0,0 +1,11 @@
1
+ class NewRelic::MetricParser::ActiveRecord < NewRelic::MetricParser
2
+ def is_active_record? ; true; end
3
+
4
+ def model_class
5
+ return segments[1]
6
+ end
7
+
8
+ def developer_name
9
+ "#{model_class}##{segments.last}"
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ class NewRelic::MetricParser::Controller < NewRelic::MetricParser
2
+
3
+ def is_controller?
4
+ true
5
+ end
6
+
7
+ def controller_name
8
+ segments[1..-2].join('/').camelize+"Controller"
9
+ end
10
+
11
+ def action_name
12
+ if segments[-1] =~ /^\(other\)$/
13
+ '(template only)'
14
+ else
15
+ segments[-1]
16
+ end
17
+ end
18
+
19
+ def developer_name
20
+ "#{controller_name}##{action_name}"
21
+ end
22
+
23
+ # return the cpu measuring equivalent. It may be nil since this metric was not
24
+ # present in earlier versions of the agent.
25
+ def cpu_metric
26
+ Metric.lookup((["ControllerCPU"] + segments[1..-1]).join('/'), "", :create => false)
27
+ end
28
+
29
+ def short_name
30
+ # standard controller actions
31
+ if segments.length > 1
32
+ url
33
+ else
34
+ 'All Controller Actions'
35
+ end
36
+ end
37
+
38
+ def url
39
+ '/' + segments[1..-1].join('/')
40
+ end
41
+
42
+ # this is used to match transaction traces to controller actions.
43
+ # TT's don't have a preceding slash :P
44
+ def tt_path
45
+ segments[1..-1].join('/')
46
+ end
47
+
48
+ def call_rate_suffix
49
+ 'rpm'
50
+ end
51
+ end