genki-newrelic_rpm 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/CHANGELOG +316 -0
  2. data/LICENSE +37 -0
  3. data/Manifest +156 -0
  4. data/README.md +138 -0
  5. data/Rakefile +22 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic_cmd +4 -0
  8. data/cert/cacert.pem +34 -0
  9. data/genki-newrelic_rpm.gemspec +32 -0
  10. data/init.rb +38 -0
  11. data/install.rb +37 -0
  12. data/lib/new_relic/agent.rb +280 -0
  13. data/lib/new_relic/agent/agent.rb +627 -0
  14. data/lib/new_relic/agent/chained_call.rb +13 -0
  15. data/lib/new_relic/agent/collection_helper.rb +61 -0
  16. data/lib/new_relic/agent/error_collector.rb +125 -0
  17. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  18. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +83 -0
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +368 -0
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
  22. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +132 -0
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +21 -0
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  25. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +13 -0
  26. data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
  27. data/lib/new_relic/agent/instrumentation/net.rb +12 -0
  28. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
  29. data/lib/new_relic/agent/instrumentation/rack.rb +77 -0
  30. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  31. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  32. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +38 -0
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +27 -0
  34. data/lib/new_relic/agent/instrumentation/sinatra.rb +39 -0
  35. data/lib/new_relic/agent/method_tracer.rb +277 -0
  36. data/lib/new_relic/agent/patch_const_missing.rb +125 -0
  37. data/lib/new_relic/agent/sampler.rb +12 -0
  38. data/lib/new_relic/agent/samplers/cpu_sampler.rb +49 -0
  39. data/lib/new_relic/agent/samplers/memory_sampler.rb +137 -0
  40. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  41. data/lib/new_relic/agent/shim_agent.rb +21 -0
  42. data/lib/new_relic/agent/stats_engine.rb +24 -0
  43. data/lib/new_relic/agent/stats_engine/metric_stats.rb +111 -0
  44. data/lib/new_relic/agent/stats_engine/samplers.rb +71 -0
  45. data/lib/new_relic/agent/stats_engine/transactions.rb +155 -0
  46. data/lib/new_relic/agent/transaction_sampler.rb +319 -0
  47. data/lib/new_relic/agent/worker_loop.rb +118 -0
  48. data/lib/new_relic/commands/deployments.rb +145 -0
  49. data/lib/new_relic/commands/new_relic_commands.rb +30 -0
  50. data/lib/new_relic/control.rb +436 -0
  51. data/lib/new_relic/control/external.rb +13 -0
  52. data/lib/new_relic/control/merb.rb +22 -0
  53. data/lib/new_relic/control/rails.rb +143 -0
  54. data/lib/new_relic/control/ruby.rb +34 -0
  55. data/lib/new_relic/control/sinatra.rb +14 -0
  56. data/lib/new_relic/histogram.rb +89 -0
  57. data/lib/new_relic/local_environment.rb +285 -0
  58. data/lib/new_relic/merbtasks.rb +6 -0
  59. data/lib/new_relic/metric_data.rb +44 -0
  60. data/lib/new_relic/metric_parser.rb +120 -0
  61. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  62. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  63. data/lib/new_relic/metric_parser/active_record.rb +25 -0
  64. data/lib/new_relic/metric_parser/controller.rb +54 -0
  65. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  66. data/lib/new_relic/metric_parser/errors.rb +6 -0
  67. data/lib/new_relic/metric_parser/external.rb +50 -0
  68. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  69. data/lib/new_relic/metric_parser/view.rb +61 -0
  70. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  71. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  72. data/lib/new_relic/metric_spec.rb +52 -0
  73. data/lib/new_relic/metrics.rb +7 -0
  74. data/lib/new_relic/noticed_error.rb +25 -0
  75. data/lib/new_relic/rack/metric_app.rb +56 -0
  76. data/lib/new_relic/rack/newrelic.ru +25 -0
  77. data/lib/new_relic/rack/newrelic.yml +25 -0
  78. data/lib/new_relic/rack_app.rb +5 -0
  79. data/lib/new_relic/recipes.rb +82 -0
  80. data/lib/new_relic/stats.rb +360 -0
  81. data/lib/new_relic/transaction_analysis.rb +121 -0
  82. data/lib/new_relic/transaction_sample.rb +583 -0
  83. data/lib/new_relic/version.rb +54 -0
  84. data/lib/new_relic_api.rb +315 -0
  85. data/lib/newrelic_rpm.rb +40 -0
  86. data/lib/tasks/all.rb +4 -0
  87. data/lib/tasks/install.rake +7 -0
  88. data/lib/tasks/tests.rake +13 -0
  89. data/newrelic.yml +214 -0
  90. data/recipes/newrelic.rb +6 -0
  91. data/test/active_record_fixtures.rb +55 -0
  92. data/test/config/newrelic.yml +46 -0
  93. data/test/config/test_control.rb +39 -0
  94. data/test/new_relic/agent/active_record_instrumentation_test.rb +234 -0
  95. data/test/new_relic/agent/agent_controller_test.rb +107 -0
  96. data/test/new_relic/agent/agent_test.rb +117 -0
  97. data/test/new_relic/agent/agent_test_controller.rb +44 -0
  98. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  99. data/test/new_relic/agent/collection_helper_test.rb +118 -0
  100. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +76 -0
  101. data/test/new_relic/agent/error_collector_test.rb +155 -0
  102. data/test/new_relic/agent/method_tracer_test.rb +335 -0
  103. data/test/new_relic/agent/metric_data_test.rb +56 -0
  104. data/test/new_relic/agent/mock_ar_connection.rb +40 -0
  105. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  106. data/test/new_relic/agent/net_instrumentation_test.rb +51 -0
  107. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  108. data/test/new_relic/agent/stats_engine/samplers_test.rb +78 -0
  109. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +177 -0
  110. data/test/new_relic/agent/task_instrumentation_test.rb +67 -0
  111. data/test/new_relic/agent/testable_agent.rb +13 -0
  112. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  113. data/test/new_relic/agent/transaction_sample_test.rb +146 -0
  114. data/test/new_relic/agent/transaction_sampler_test.rb +387 -0
  115. data/test/new_relic/agent/worker_loop_test.rb +103 -0
  116. data/test/new_relic/control_test.rb +94 -0
  117. data/test/new_relic/deployments_api_test.rb +68 -0
  118. data/test/new_relic/environment_test.rb +75 -0
  119. data/test/new_relic/metric_parser_test.rb +172 -0
  120. data/test/new_relic/metric_spec_test.rb +177 -0
  121. data/test/new_relic/shim_agent_test.rb +9 -0
  122. data/test/new_relic/stats_test.rb +291 -0
  123. data/test/new_relic/version_number_test.rb +74 -0
  124. data/test/test_helper.rb +38 -0
  125. data/test/ui/newrelic_controller_test.rb +14 -0
  126. data/test/ui/newrelic_helper_test.rb +53 -0
  127. data/ui/controllers/newrelic_controller.rb +214 -0
  128. data/ui/helpers/google_pie_chart.rb +55 -0
  129. data/ui/helpers/newrelic_helper.rb +314 -0
  130. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  131. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  132. data/ui/views/newrelic/_sample.rhtml +15 -0
  133. data/ui/views/newrelic/_segment.rhtml +28 -0
  134. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  135. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  136. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  137. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  138. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  139. data/ui/views/newrelic/_sql_row.rhtml +11 -0
  140. data/ui/views/newrelic/_stack_trace.rhtml +30 -0
  141. data/ui/views/newrelic/_table.rhtml +12 -0
  142. data/ui/views/newrelic/explain_sql.rhtml +42 -0
  143. data/ui/views/newrelic/images/arrow-close.png +0 -0
  144. data/ui/views/newrelic/images/arrow-open.png +0 -0
  145. data/ui/views/newrelic/images/blue_bar.gif +0 -0
  146. data/ui/views/newrelic/images/file_icon.png +0 -0
  147. data/ui/views/newrelic/images/gray_bar.gif +0 -0
  148. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  149. data/ui/views/newrelic/images/textmate.png +0 -0
  150. data/ui/views/newrelic/index.rhtml +45 -0
  151. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  152. data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
  153. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  154. data/ui/views/newrelic/show_sample.rhtml +77 -0
  155. data/ui/views/newrelic/show_source.rhtml +3 -0
  156. data/ui/views/newrelic/stylesheets/style.css +433 -0
  157. data/ui/views/newrelic/threads.rhtml +52 -0
  158. metadata +327 -0
@@ -0,0 +1,90 @@
1
+
2
+ # NewRelic instrumentation for DataMapper
3
+ # For now, we have to refer to all db metrics as "ActiveRecord"
4
+ if defined? DataMapper
5
+
6
+ DataMapper::Model.class_eval do
7
+ add_method_tracer :get, 'ActiveRecord/#{self.name}/find'
8
+ add_method_tracer :first, 'ActiveRecord/#{self.name}/find'
9
+ add_method_tracer :first_or_create, 'ActiveRecord/#{self.name}/find'
10
+ add_method_tracer :all, 'ActiveRecord/#{self.name}/find_all'
11
+ end
12
+ DataMapper::Adapters::DataObjectsAdapter.class_eval do
13
+
14
+ @@my_sql_defined = defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
15
+ @@postgres_defined = defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
16
+
17
+ for method in [:read_many, :read_one] do
18
+ add_method_tracer method, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/find' # Need to get the model somehow
19
+ add_method_tracer method, 'ActiveRecord/find', :push_scope => false
20
+ add_method_tracer method, 'ActiveRecord/all', :push_scope => false
21
+ end
22
+ for method in [:execute, :query] do
23
+ add_method_tracer method, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/execute' # Need to get the model somehow
24
+ add_method_tracer method, 'ActiveRecord/all', :push_scope => false
25
+ end
26
+ for method in [:create, :update]do
27
+ add_method_tracer method, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
28
+ add_method_tracer method, 'ActiveRecord/save', :push_scope => false
29
+ end
30
+ add_method_tracer :delete, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
31
+ add_method_tracer :delete, 'ActiveRecord/destroy', :push_scope => false
32
+
33
+ def log_with_newrelic_instrumentation(sql, name, &block)
34
+ # if we aren't in a blamed context, then add one so that we can see that
35
+ # controllers are calling SQL directly
36
+ # we check scope_depth vs 2 since the controller is 1, and the
37
+ #
38
+ if NewRelic::Agent.instance.transaction_sampler.scope_depth < 2
39
+ self.class.trace_method_execution "Database/DirectSQL", true, true do
40
+ log_with_capture_sql(sql, name, &block)
41
+ end
42
+ else
43
+ log_with_capture_sql(sql, name, &block)
44
+ end
45
+ end
46
+
47
+ def log_with_capture_sql(sql, name, &block)
48
+ if @@my_sql_defined && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
49
+ config = @config
50
+ elsif @@postgres_defined && self.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
51
+ config = @config
52
+ else
53
+ config = nil
54
+ end
55
+
56
+ t0 = Time.now
57
+ result = log_without_newrelic_instrumentation(sql, name, &block)
58
+
59
+ NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, config, Time.now - t0)
60
+
61
+ result
62
+ end
63
+
64
+ # Compare with #alias_method_chain, which is not available in
65
+ # Rails 1.1:
66
+ #alias_method :log_without_newrelic_instrumentation, :log
67
+ #alias_method :log, :log_with_newrelic_instrumentation
68
+
69
+ =begin
70
+ # instrumentation for associations
71
+ module Associations
72
+ class AssociationCollection
73
+ add_method_tracer :delete, 'ActiveRecord/#{@owner.class.name}/association delete'
74
+ end
75
+
76
+ def HasAndBelongsToManyAssociation
77
+ add_method_tracer :find, 'ActiveRecord/#{@owner.class.name}/association find'
78
+ add_method_tracer :create_record, 'ActiveRecord/#{@owner.class.name}/association create'
79
+ add_method_tracer :insert_record, 'ActiveRecord/#{@owner.class.name}/association insert'
80
+ end
81
+
82
+ class HasManyAssociation
83
+ # add_method_tracer :find, 'ActiveRecord/#{@owner.class.name}/association find'
84
+ # add_method_tracer :insert_record, 'ActiveRecord/#{@owner.class.name}/association insert'
85
+ # add_method_tracer :create_record, 'ActiveRecord/#{@owner.class.name}/association create'
86
+ end
87
+ end
88
+ =end
89
+ end
90
+ end
@@ -0,0 +1,132 @@
1
+ # We have to patch the mongrel dispatcher live since the classes
2
+ # aren't defined when our instrumentation loads
3
+ # To use this module, you need to monkey patch a method newrelic_response_code
4
+ # which will return the response status code when the dispatcher finishes.
5
+ module NewRelic::Agent::Instrumentation
6
+ module DispatcherInstrumentation
7
+ extend self
8
+ def newrelic_dispatcher_start
9
+ # Put the current time on the thread. Can't put in @ivar because this could
10
+ # be a class or instance context
11
+ newrelic_dispatcher_start_time = Time.now.to_f
12
+ Thread.current[:newrelic_dispatcher_start] = newrelic_dispatcher_start_time
13
+ NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_start newrelic_dispatcher_start_time
14
+ # capture the time spent in the mongrel queue, if running in mongrel. This is the
15
+ # current time less the timestamp placed in 'started_on' by mongrel.
16
+ mongrel_start = Thread.current[:started_on]
17
+ mongrel_queue_stat.trace_call(newrelic_dispatcher_start_time - mongrel_start.to_f) if mongrel_start
18
+ NewRelic::Agent.agent.start_transaction
19
+
20
+ # Reset the flag indicating the controller action should be ignored.
21
+ # It may be set by the action to either true or false or left nil meaning false
22
+ Thread.current[:newrelic_ignore_controller] = nil
23
+ end
24
+
25
+ def newrelic_dispatcher_finish
26
+ #puts @env.to_a.map{|k,v| "#{'%32s' % k}: #{v.inspect[0..64]}"}.join("\n")
27
+ dispatcher_end_time = Time.now.to_f
28
+ NewRelic::Agent.agent.end_transaction
29
+ NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_finish dispatcher_end_time
30
+ unless Thread.current[:newrelic_ignore_controller]
31
+ elapsed_time = dispatcher_end_time - Thread.current[:newrelic_dispatcher_start]
32
+ # Store the response header
33
+ response_code = newrelic_response_code
34
+ if response_code
35
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope("HTTP/Response/#{response_code}").trace_call(elapsed_time)
36
+ end
37
+ # Store the response time
38
+ dispatch_stat.trace_call(elapsed_time)
39
+ NewRelic::Agent.instance.histogram.process(elapsed_time)
40
+ end
41
+ end
42
+ # Should be implemented in the dispatcher class
43
+ def newrelic_response_code; end
44
+
45
+ # Used only when no before/after callbacks are available with
46
+ # the dispatcher, such as Rails before 2.0
47
+ def dispatch_newrelic(*args)
48
+ newrelic_dispatcher_start
49
+ begin
50
+ dispatch_without_newrelic(*args)
51
+ ensure
52
+ newrelic_dispatcher_finish
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def dispatch_stat
59
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'HttpDispatcher'
60
+ end
61
+
62
+ def mongrel_queue_stat
63
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'WebFrontend/Mongrel/Average Queue Time'
64
+ end
65
+
66
+ # This won't work with Rails 2.2 multi-threading
67
+ module BusyCalculator
68
+ extend self
69
+ # the fraction of the sample period that the dispatcher was busy
70
+
71
+ def dispatcher_start(time)
72
+ @lock.synchronize do
73
+ @entrypoint_stack.push time
74
+ end
75
+ end
76
+
77
+ def dispatcher_finish(time)
78
+ @lock.synchronize do
79
+ NewRelic::Control.instance.log.error("Stack underflow tracking dispatcher entry and exit!\n #{caller.join(" \n")}") and return if @entrypoint_stack.empty?
80
+ @accumulator += (time - @entrypoint_stack.pop)
81
+ end
82
+ end
83
+
84
+ def busy_count
85
+ @entrypoint_stack.size
86
+ end
87
+ def reset
88
+ @entrypoint_stack = []
89
+ @lock = Mutex.new
90
+ @accumulator = 0
91
+ @harvest_start = Time.now.to_f
92
+ end
93
+
94
+ self.reset
95
+
96
+ # Called before uploading to to the server to collect current busy stats.
97
+ def harvest_busy
98
+ busy = 0
99
+ t0 = Time.now.to_f
100
+ @lock.synchronize do
101
+ busy = @accumulator
102
+ @accumulator = 0
103
+
104
+ # Walk through the stack and capture all times up to
105
+ # now for entrypoints
106
+ @entrypoint_stack.size.times do |frame|
107
+ busy += (t0 - @entrypoint_stack[frame])
108
+ @entrypoint_stack[frame] = t0
109
+ end
110
+
111
+ end
112
+
113
+ busy = 0.0 if busy < 0.0 # don't go below 0%
114
+
115
+ time_window = (t0 - @harvest_start)
116
+ time_window = 1.0 if time_window == 0.0 # protect against divide by zero
117
+
118
+ busy = busy / time_window
119
+
120
+ instance_busy_stats.record_data_point busy unless busy == 0
121
+ @harvest_start = t0
122
+ end
123
+ private
124
+ def instance_busy_stats
125
+ # Late binding on the Instance/busy stats
126
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'Instance/Busy'
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+ end
@@ -0,0 +1,21 @@
1
+ # NOTE there are multiple implementations of the MemCache client in Ruby,
2
+ # each with slightly different API's and semantics.
3
+ # See:
4
+ # http://www.deveiate.org/code/Ruby-MemCache/ (Gem: Ruby-MemCache)
5
+ # http://dev.robotcoop.com/Libraries/memcache-client/ (Gem: memcache-client)
6
+ MemCache.class_eval do
7
+ add_method_tracer :get, 'MemCache/read' if self.method_defined? :get
8
+ add_method_tracer :get_multi, 'MemCache/read' if self.method_defined? :get_multi
9
+ %w[set add incr decr delete].each do | method |
10
+ add_method_tracer method, 'MemCache/write' if self.method_defined? method
11
+ end
12
+ end if defined? MemCache
13
+
14
+ # Support for libmemcached through Evan Weaver's memcached wrapper
15
+ # http://blog.evanweaver.com/files/doc/fauna/memcached/classes/Memcached.html
16
+ Memcached.class_eval do
17
+ add_method_tracer :get, 'MemCache/read' if self.method_defined? :get
18
+ %w[set add increment decrement delete replace append prepend cas].each do | method |
19
+ add_method_tracer method, "MemCache/write" if self.method_defined? method
20
+ end
21
+ end if defined? Memcached
@@ -0,0 +1,26 @@
1
+ require 'set'
2
+ require 'merb-core/controller/merb_controller'
3
+
4
+ Merb::Controller.class_eval do
5
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
+
7
+ class_inheritable_accessor :do_not_trace
8
+ class_inheritable_accessor :ignore_apdex
9
+
10
+ def self.newrelic_write_attr(attr_name, value) # :nodoc:
11
+ self.send "#{attr_name}=", attr_name, value
12
+ end
13
+
14
+ def self.newrelic_read_attr(attr_name) # :nodoc:
15
+ self.send attr_name
16
+ end
17
+
18
+ protected
19
+ # determine the path that is used in the metric name for
20
+ # the called controller action
21
+ def newrelic_metric_path(action)
22
+ "#{controller_name}/#{action}"
23
+ end
24
+ alias_method :perform_action_without_newrelic_trace, :_dispatch
25
+ alias_method :_dispatch, :perform_action_with_newrelic_trace
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'merb-core/dispatch/dispatcher'
2
+ # NewRelic RPM instrumentation for http request dispatching (Routes mapping)
3
+ Merb::Request.class_eval do
4
+
5
+ include NewRelic::Agent::Instrumentation::DispatcherInstrumentation
6
+
7
+ alias_method :dispatch_without_newrelic, :handle
8
+ alias_method :handle, :dispatch_newrelic
9
+ def newrelic_response_code
10
+ # Don't have an easy way to get the HTTP status from here yet
11
+ nil
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ # Hook in the notification to merb
2
+ error_notifier = Proc.new {
3
+ if request.exceptions #check that there's actually an exception
4
+ NewRelic::Agent.agent.error_collector.notice_error(request.exceptions.first, request, "#{params[:controller]}/#{params[:action]}", params)
5
+ end
6
+ }
7
+ Merb::Dispatcher::DefaultException.before error_notifier
8
+ Exceptions.before error_notifier
@@ -0,0 +1,12 @@
1
+ # ActiveMerchant Instrumentation.
2
+
3
+ if defined? Net::HTTP
4
+ # operations = %w[request]
5
+ # for op in operations do
6
+ Net::HTTP.class_eval do
7
+ add_method_tracer "request", 'External/#{@address}/Net::HTTP/#{args[0].method}'# + op
8
+ add_method_tracer "request", 'External/#{@address}/all', :push_scope => false
9
+ add_method_tracer "request", 'External/all', :push_scope => false
10
+ end
11
+ # end
12
+ end
@@ -0,0 +1,20 @@
1
+ if defined?(PhusionPassenger)
2
+ NewRelic::Control.instance.log.debug "Installing Passenger event hooks."
3
+
4
+ PhusionPassenger.on_event(:stopping_worker_process) do
5
+ NewRelic::Control.instance.log.info "Passenger stopping this process, shutdown the agent."
6
+ NewRelic::Agent.instance.shutdown
7
+ end
8
+
9
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
10
+ if forked
11
+ # We want to reset the stats from the stats engine in case any carried
12
+ # over into the spawned process. Don't clear them in case any were
13
+ # cached.
14
+ NewRelic::Agent.instance.stats_engine.reset_stats
15
+ else
16
+ # We're in conservative spawning mode. We don't need to do anything.
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,77 @@
1
+
2
+
3
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module Instrumentation
8
+ # == Instrumentation for Rack
9
+ #
10
+ # New Relic will instrument a #call method as if it were a controller
11
+ # action, collecting transaction traces and errors. The middleware will
12
+ # be identified only by it's class, so if you want to instrument multiple
13
+ # actions in a middleware, you need to use
14
+ # NewRelic::Agent::Instrumentation::ControllerInstrumentation::ClassMethods#add_transaction_tracer
15
+ #
16
+ # Example:
17
+ # require 'new_relic/agent/instrumentation/rack'
18
+ # class Middleware
19
+ # def call(env)
20
+ # ...
21
+ # end
22
+ # # Do the include after the call method is defined:
23
+ # include NewRelic::Agent::Instrumentation::Rack
24
+ # end
25
+ #
26
+ # == Instrumenting Metal
27
+ #
28
+ # If you are using Metal, be sure and extend the your Metal class with the
29
+ # Rack instrumentation:
30
+ #
31
+ # require 'new_relic/agent/instrumentation/rack'
32
+ # class MetalApp
33
+ # def self.call(env)
34
+ # ...
35
+ # end
36
+ # # Do the include after the call method is defined:
37
+ # extend NewRelic::Agent::Instrumentation::Rack
38
+ # end
39
+ #
40
+ # == Overriding the metric name
41
+ # By default the middleware is identified only by its class, but if you want to
42
+ # be more specific and pass in name, then omit including the Rack instrumentation
43
+ # and instead follow this example:
44
+ #
45
+ # require 'new_relic/agent/instrumentation/controller_instrumentation'
46
+ # class Middleware
47
+ # def call(env)
48
+ # ...
49
+ # end
50
+ # add_transaction_tracer :call, :category => :rack, :name => 'my app'
51
+ # end
52
+ #
53
+ module Rack
54
+ def call_with_newrelic(*args)
55
+ perform_action_with_newrelic_trace(:category => :rack) do
56
+ call_without_newrelic(*args)
57
+ end
58
+ end
59
+ def self.included middleware #:nodoc:
60
+ middleware.class_eval do
61
+ alias call_without_newrelic call
62
+ alias call call_with_newrelic
63
+ end
64
+ end
65
+ include ControllerInstrumentation
66
+ def self.extended middleware #:nodoc:
67
+ middleware.class_eval do
68
+ class << self
69
+ alias call_without_newrelic call
70
+ alias call call_with_newrelic
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,59 @@
1
+
2
+ if defined? ActionController
3
+
4
+ case Rails::VERSION::STRING
5
+
6
+ when /^(1\.|2\.0)/ # Rails 1.* - 2.0
7
+ ActionController::Base.class_eval do
8
+ add_method_tracer :render, 'View/#{newrelic_metric_path}/Rendering'
9
+ end
10
+
11
+ when /^2\.1\./ # Rails 2.1
12
+ ActionView::PartialTemplate.class_eval do
13
+ add_method_tracer :render, 'View/#{path_without_extension}.#{@view.template_format}.#{extension}/Partial'
14
+ end
15
+ # this is for template rendering, as opposed to partial rendering.
16
+ ActionView::Template.class_eval do
17
+ add_method_tracer :render, 'View/#{path_without_extension}.#{@view.template_format}.#{extension}/Rendering'
18
+ end
19
+
20
+ when /^2\./ # Rails 2.2-2.*
21
+ ActionView::RenderablePartial.module_eval do
22
+ add_method_tracer :render_partial, 'View/#{path}/Partial'
23
+ end
24
+ ActionView::Template.class_eval do
25
+ add_method_tracer :render, 'View/#{path}/Rendering'
26
+ end
27
+ end unless NewRelic::Control.instance['disable_view_instrumentation']
28
+
29
+ ActionController::Base.class_eval do
30
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
31
+
32
+ # Compare with #alias_method_chain, which is not available in
33
+ # Rails 1.1:
34
+ alias_method :perform_action_without_newrelic_trace, :perform_action
35
+ alias_method :perform_action, :perform_action_with_newrelic_trace
36
+ private :perform_action
37
+
38
+ def self.newrelic_write_attr(attr_name, value) # :nodoc:
39
+ write_inheritable_attribute(attr_name, value)
40
+ end
41
+
42
+ def self.newrelic_read_attr(attr_name) # :nodoc:
43
+ read_inheritable_attribute(attr_name)
44
+ end
45
+
46
+ # determine the path that is used in the metric name for
47
+ # the called controller action
48
+ def newrelic_metric_path(action_name_override = nil)
49
+ action_part = action_name_override || action_name
50
+ if action_name_override || self.class.action_methods.include?(action_part)
51
+ "#{self.class.controller_path}/#{action_part}"
52
+ else
53
+ "#{self.class.controller_path}/(other)"
54
+ end
55
+ end
56
+ end
57
+ else
58
+ NewRelic::Agent.instance.log.debug "WARNING: ActionController instrumentation not added"
59
+ end