newrelic_rpm 2.9.9 → 2.10.3

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 (120) hide show
  1. data/CHANGELOG +117 -49
  2. data/bin/mongrel_rpm +2 -2
  3. data/install.rb +42 -33
  4. data/lib/new_relic/agent.rb +149 -39
  5. data/lib/new_relic/agent/agent.rb +139 -122
  6. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  7. data/lib/new_relic/agent/collection_helper.rb +11 -2
  8. data/lib/new_relic/agent/error_collector.rb +33 -27
  9. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +30 -26
  10. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  11. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +316 -105
  12. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  13. data/lib/new_relic/agent/instrumentation/memcache.rb +18 -12
  14. data/lib/new_relic/agent/instrumentation/merb/errors.rb +2 -1
  15. data/lib/new_relic/agent/instrumentation/metric_frame.rb +258 -0
  16. data/lib/new_relic/agent/instrumentation/net.rb +7 -11
  17. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rack.rb +109 -0
  19. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -5
  20. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -7
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  22. data/lib/new_relic/agent/method_tracer.rb +305 -150
  23. data/lib/new_relic/agent/sampler.rb +34 -0
  24. data/lib/new_relic/agent/samplers/cpu_sampler.rb +11 -1
  25. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  26. data/lib/new_relic/agent/samplers/memory_sampler.rb +22 -10
  27. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  28. data/lib/new_relic/agent/shim_agent.rb +10 -0
  29. data/lib/new_relic/agent/stats_engine.rb +16 -278
  30. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  31. data/lib/new_relic/agent/stats_engine/samplers.rb +81 -0
  32. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  33. data/lib/new_relic/agent/transaction_sampler.rb +73 -67
  34. data/lib/new_relic/agent/worker_loop.rb +69 -68
  35. data/lib/new_relic/commands/deployments.rb +4 -6
  36. data/lib/new_relic/control.rb +121 -60
  37. data/lib/new_relic/control/external.rb +13 -0
  38. data/lib/new_relic/control/merb.rb +2 -0
  39. data/lib/new_relic/control/rails.rb +16 -6
  40. data/lib/new_relic/control/ruby.rb +8 -5
  41. data/lib/new_relic/control/sinatra.rb +18 -0
  42. data/lib/new_relic/delayed_job_injection.rb +25 -0
  43. data/lib/new_relic/histogram.rb +89 -0
  44. data/lib/new_relic/local_environment.rb +64 -30
  45. data/lib/new_relic/metric_data.rb +15 -6
  46. data/lib/new_relic/metric_parser.rb +14 -1
  47. data/lib/new_relic/metric_parser/active_record.rb +14 -0
  48. data/lib/new_relic/metric_parser/controller.rb +5 -2
  49. data/lib/new_relic/metric_parser/external.rb +50 -0
  50. data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
  51. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  52. data/lib/new_relic/metric_spec.rb +39 -20
  53. data/lib/new_relic/metrics.rb +9 -7
  54. data/lib/new_relic/noticed_error.rb +6 -8
  55. data/lib/new_relic/rack/metric_app.rb +5 -4
  56. data/lib/new_relic/rack/{newrelic.ru → mongrel_rpm.ru} +4 -4
  57. data/lib/new_relic/rack/newrelic.yml +1 -0
  58. data/lib/new_relic/{rack.rb → rack_app.rb} +0 -0
  59. data/lib/new_relic/recipes.rb +1 -1
  60. data/lib/new_relic/stats.rb +40 -26
  61. data/lib/new_relic/transaction_analysis.rb +5 -2
  62. data/lib/new_relic/transaction_sample.rb +134 -55
  63. data/lib/new_relic/version.rb +27 -20
  64. data/lib/new_relic_api.rb +67 -47
  65. data/lib/newrelic_rpm.rb +5 -5
  66. data/lib/tasks/tests.rake +2 -0
  67. data/newrelic.yml +69 -29
  68. data/test/active_record_fixtures.rb +2 -2
  69. data/test/config/newrelic.yml +4 -7
  70. data/test/config/test_control.rb +1 -2
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +115 -31
  72. data/test/new_relic/agent/agent_controller_test.rb +274 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +42 -6
  74. data/test/new_relic/agent/busy_calculator_test.rb +79 -0
  75. data/test/new_relic/agent/collection_helper_test.rb +10 -3
  76. data/test/new_relic/agent/error_collector_test.rb +35 -17
  77. data/test/new_relic/agent/method_tracer_test.rb +60 -20
  78. data/test/new_relic/agent/metric_data_test.rb +2 -2
  79. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  80. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  81. data/test/new_relic/agent/{agent_test.rb → rpm_agent_test.rb} +26 -5
  82. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  83. data/test/new_relic/{samplers_test.rb → agent/stats_engine/samplers_test.rb} +23 -22
  84. data/test/new_relic/agent/{stats_engine_test.rb → stats_engine/stats_engine_test.rb} +19 -101
  85. data/test/new_relic/agent/task_instrumentation_test.rb +176 -0
  86. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -2
  87. data/test/new_relic/agent/transaction_sample_test.rb +53 -38
  88. data/test/new_relic/agent/transaction_sampler_test.rb +101 -33
  89. data/test/new_relic/agent/worker_loop_test.rb +16 -14
  90. data/test/new_relic/control_test.rb +26 -13
  91. data/test/new_relic/metric_parser_test.rb +31 -1
  92. data/test/new_relic/metric_spec_test.rb +2 -2
  93. data/test/new_relic/stats_test.rb +0 -8
  94. data/test/new_relic/version_number_test.rb +31 -1
  95. data/test/test_helper.rb +37 -1
  96. data/ui/controllers/newrelic_controller.rb +19 -11
  97. data/ui/helpers/google_pie_chart.rb +5 -11
  98. data/ui/helpers/newrelic_helper.rb +40 -35
  99. data/ui/views/layouts/newrelic_default.rhtml +7 -7
  100. data/ui/views/newrelic/_sample.rhtml +5 -1
  101. data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
  102. data/ui/views/newrelic/images/textmate.png +0 -0
  103. data/ui/views/newrelic/index.rhtml +13 -1
  104. data/ui/views/newrelic/show_sample.rhtml +5 -2
  105. data/ui/views/newrelic/stylesheets/style.css +54 -3
  106. metadata +65 -145
  107. data/Manifest +0 -143
  108. data/Rakefile +0 -22
  109. data/init.rb +0 -38
  110. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +0 -127
  111. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +0 -14
  112. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +0 -13
  113. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +0 -38
  114. data/lib/new_relic/agent/patch_const_missing.rb +0 -125
  115. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +0 -22
  116. data/lib/new_relic/metric_parser/database.rb +0 -23
  117. data/newrelic_rpm.gemspec +0 -35
  118. data/test/new_relic/agent/classloader_patch_test.rb +0 -56
  119. data/test/new_relic/agent/controller_test.rb +0 -107
  120. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +0 -70
data/Manifest DELETED
@@ -1,143 +0,0 @@
1
- bin/mongrel_rpm
2
- bin/newrelic_cmd
3
- cert/cacert.pem
4
- CHANGELOG
5
- init.rb
6
- install.rb
7
- lib/new_relic/agent/agent.rb
8
- lib/new_relic/agent/chained_call.rb
9
- lib/new_relic/agent/collection_helper.rb
10
- lib/new_relic/agent/error_collector.rb
11
- lib/new_relic/agent/instrumentation/active_merchant.rb
12
- lib/new_relic/agent/instrumentation/active_record_instrumentation.rb
13
- lib/new_relic/agent/instrumentation/controller_instrumentation.rb
14
- lib/new_relic/agent/instrumentation/data_mapper.rb
15
- lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb
16
- lib/new_relic/agent/instrumentation/error_instrumentation.rb
17
- lib/new_relic/agent/instrumentation/memcache.rb
18
- lib/new_relic/agent/instrumentation/merb/controller.rb
19
- lib/new_relic/agent/instrumentation/merb/dispatcher.rb
20
- lib/new_relic/agent/instrumentation/merb/errors.rb
21
- lib/new_relic/agent/instrumentation/net.rb
22
- lib/new_relic/agent/instrumentation/passenger_instrumentation.rb
23
- lib/new_relic/agent/instrumentation/rails/action_controller.rb
24
- lib/new_relic/agent/instrumentation/rails/action_web_service.rb
25
- lib/new_relic/agent/instrumentation/rails/dispatcher.rb
26
- lib/new_relic/agent/instrumentation/rails/errors.rb
27
- lib/new_relic/agent/method_tracer.rb
28
- lib/new_relic/agent/patch_const_missing.rb
29
- lib/new_relic/agent/sampler.rb
30
- lib/new_relic/agent/samplers/cpu_sampler.rb
31
- lib/new_relic/agent/samplers/memory_sampler.rb
32
- lib/new_relic/agent/samplers/mongrel_sampler.rb
33
- lib/new_relic/agent/shim_agent.rb
34
- lib/new_relic/agent/stats_engine.rb
35
- lib/new_relic/agent/transaction_sampler.rb
36
- lib/new_relic/agent/worker_loop.rb
37
- lib/new_relic/agent.rb
38
- lib/new_relic/commands/deployments.rb
39
- lib/new_relic/commands/new_relic_commands.rb
40
- lib/new_relic/control/merb.rb
41
- lib/new_relic/control/rails.rb
42
- lib/new_relic/control/ruby.rb
43
- lib/new_relic/control.rb
44
- lib/new_relic/local_environment.rb
45
- lib/new_relic/merbtasks.rb
46
- lib/new_relic/metric_data.rb
47
- lib/new_relic/metric_parser/action_mailer.rb
48
- lib/new_relic/metric_parser/active_merchant.rb
49
- lib/new_relic/metric_parser/active_record.rb
50
- lib/new_relic/metric_parser/controller.rb
51
- lib/new_relic/metric_parser/controller_cpu.rb
52
- lib/new_relic/metric_parser/database.rb
53
- lib/new_relic/metric_parser/errors.rb
54
- lib/new_relic/metric_parser/mem_cache.rb
55
- lib/new_relic/metric_parser/view.rb
56
- lib/new_relic/metric_parser/web_service.rb
57
- lib/new_relic/metric_parser.rb
58
- lib/new_relic/metric_spec.rb
59
- lib/new_relic/metrics.rb
60
- lib/new_relic/noticed_error.rb
61
- lib/new_relic/rack/metric_app.rb
62
- lib/new_relic/rack/newrelic.ru
63
- lib/new_relic/rack/newrelic.yml
64
- lib/new_relic/rack.rb
65
- lib/new_relic/recipes.rb
66
- lib/new_relic/stats.rb
67
- lib/new_relic/transaction_analysis.rb
68
- lib/new_relic/transaction_sample.rb
69
- lib/new_relic/version.rb
70
- lib/new_relic_api.rb
71
- lib/newrelic_rpm.rb
72
- lib/tasks/all.rb
73
- lib/tasks/install.rake
74
- lib/tasks/tests.rake
75
- LICENSE
76
- newrelic.yml
77
- Rakefile
78
- README.md
79
- recipes/newrelic.rb
80
- test/active_record_fixtures.rb
81
- test/config/newrelic.yml
82
- test/config/test_control.rb
83
- test/new_relic/agent/active_record_instrumentation_test.rb
84
- test/new_relic/agent/agent_test.rb
85
- test/new_relic/agent/agent_test_controller.rb
86
- test/new_relic/agent/classloader_patch_test.rb
87
- test/new_relic/agent/collection_helper_test.rb
88
- test/new_relic/agent/controller_test.rb
89
- test/new_relic/agent/dispatcher_instrumentation_test.rb
90
- test/new_relic/agent/error_collector_test.rb
91
- test/new_relic/agent/method_tracer_test.rb
92
- test/new_relic/agent/metric_data_test.rb
93
- test/new_relic/agent/mock_ar_connection.rb
94
- test/new_relic/agent/mock_scope_listener.rb
95
- test/new_relic/agent/stats_engine_test.rb
96
- test/new_relic/agent/testable_agent.rb
97
- test/new_relic/agent/transaction_sample_builder_test.rb
98
- test/new_relic/agent/transaction_sample_test.rb
99
- test/new_relic/agent/transaction_sampler_test.rb
100
- test/new_relic/agent/worker_loop_test.rb
101
- test/new_relic/control_test.rb
102
- test/new_relic/deployments_api_test.rb
103
- test/new_relic/environment_test.rb
104
- test/new_relic/metric_parser_test.rb
105
- test/new_relic/metric_spec_test.rb
106
- test/new_relic/samplers_test.rb
107
- test/new_relic/shim_agent_test.rb
108
- test/new_relic/stats_test.rb
109
- test/new_relic/version_number_test.rb
110
- test/test_helper.rb
111
- test/ui/newrelic_controller_test.rb
112
- test/ui/newrelic_helper_test.rb
113
- ui/controllers/newrelic_controller.rb
114
- ui/helpers/google_pie_chart.rb
115
- ui/helpers/newrelic_helper.rb
116
- ui/views/layouts/newrelic_default.rhtml
117
- ui/views/newrelic/_explain_plans.rhtml
118
- ui/views/newrelic/_sample.rhtml
119
- ui/views/newrelic/_segment.rhtml
120
- ui/views/newrelic/_segment_limit_message.rhtml
121
- ui/views/newrelic/_segment_row.rhtml
122
- ui/views/newrelic/_show_sample_detail.rhtml
123
- ui/views/newrelic/_show_sample_sql.rhtml
124
- ui/views/newrelic/_show_sample_summary.rhtml
125
- ui/views/newrelic/_sql_row.rhtml
126
- ui/views/newrelic/_stack_trace.rhtml
127
- ui/views/newrelic/_table.rhtml
128
- ui/views/newrelic/explain_sql.rhtml
129
- ui/views/newrelic/images/arrow-close.png
130
- ui/views/newrelic/images/arrow-open.png
131
- ui/views/newrelic/images/blue_bar.gif
132
- ui/views/newrelic/images/file_icon.png
133
- ui/views/newrelic/images/gray_bar.gif
134
- ui/views/newrelic/images/new_relic_rpm_desktop.gif
135
- ui/views/newrelic/index.rhtml
136
- ui/views/newrelic/javascript/prototype-scriptaculous.js
137
- ui/views/newrelic/javascript/transaction_sample.js
138
- ui/views/newrelic/sample_not_found.rhtml
139
- ui/views/newrelic/show_sample.rhtml
140
- ui/views/newrelic/show_source.rhtml
141
- ui/views/newrelic/stylesheets/style.css
142
- ui/views/newrelic/threads.rhtml
143
- Manifest
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- require 'rubygems'
2
- require 'lib/new_relic/version.rb'
3
- require 'echoe'
4
-
5
- GEM_NAME = "newrelic_rpm"
6
- GEM_VERSION = NewRelic::VERSION::STRING
7
- AUTHOR = "Bill Kayser"
8
- EMAIL = "bkayser@newrelic.com"
9
- HOMEPAGE = "http://www.newrelic.com"
10
- SUMMARY = "New Relic Ruby Performance Monitoring Agent"
11
-
12
- Echoe.new(GEM_NAME) do |p|
13
- p.author = AUTHOR
14
- p.summary = SUMMARY
15
- p.url = HOMEPAGE
16
- p.email = EMAIL
17
- p.project = 'newrelic'
18
- p.need_tar_gz = false
19
- p.need_gem = true
20
- p.ignore_pattern = %w[]
21
- end
22
-
data/init.rb DELETED
@@ -1,38 +0,0 @@
1
- # This is the initialization for the RPM Rails plugin
2
- require 'new_relic/control'
3
-
4
- # If you are having problems seeing data, be sure and check the
5
- # newrelic_agent log files.
6
- #
7
- # If you can't find any log files and you don't see anything in your
8
- # application log files, try uncommenting the two lines at the
9
- # bottom of this file to verify the plugin is being loaded,
10
- # then send the output to support@newrelic.com if you are unable to
11
- # resolve the issue.
12
-
13
- # Initializer for the NewRelic Agent
14
-
15
- # We use this to test the agent to ensure it's not loading classes inappropriately
16
- #require 'new_relic/agent/patch_const_missing'
17
- #ClassLoadingWatcher.flag_const_missing = true
18
- begin
19
- # JRuby's glassfish plugin is trying to run the Initializer twice,
20
- # which isn't a good thing so we ignore subsequent invocations here.
21
- if ! defined?(::NEWRELIC_STARTED)
22
- ::NEWRELIC_STARTED = "#{caller.join("\n")}"
23
-
24
- NewRelic::Control.instance.init_plugin(defined?(config) ? {:config => config} : {})
25
- else
26
- NewRelic::Control.instance.log.debug "Attempt to initialize the plugin twice!"
27
- NewRelic::Control.instance.log.debug "Original call: \n#{::NEWRELIC_STARTED}"
28
- NewRelic::Control.instance.log.debug "Here we are now: \n#{caller.join("\n")}"
29
- end
30
- rescue => e
31
- NewRelic::Control.instance.log! "Error initializing New Relic plugin (#{e})", :error
32
- NewRelic::Control.instance.log! e.backtrace.join("\n"), :error
33
- NewRelic::Control.instance.log! "Agent is disabled."
34
- end
35
- #ClassLoadingWatcher.flag_const_missing = nil
36
-
37
- # ::RAILS_DEFAULT_LOGGER.warn "RPM detected environment: #{NewRelic::Control.instance.local_env.to_s}, RAILS_ENV: #{RAILS_ENV}"
38
- # ::RAILS_DEFAULT_LOGGER.warn "Enabled? #{NewRelic::Control.instance.agent_enabled?}"
@@ -1,127 +0,0 @@
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
-
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[:controller_ignored] = 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[:controller_ignored]
31
- # Store the response header
32
- newrelic_dispatcher_start_time = Thread.current[:newrelic_dispatcher_start]
33
- response_code = newrelic_response_code
34
- if response_code
35
- stats = NewRelic::Agent.agent.stats_engine.get_stats_no_scope("HTTP/Response/#{response_code}")
36
- stats.trace_call(dispatcher_end_time - newrelic_dispatcher_start_time)
37
- end
38
- dispatch_stat.trace_call(dispatcher_end_time - newrelic_dispatcher_start_time)
39
- end
40
- end
41
- def newrelic_response_code
42
- raise "Must be implemented in the dispatcher class"
43
- end
44
- # Used only when no before/after callbacks are available with
45
- # the dispatcher, such as Rails before 2.0
46
- def dispatch_newrelic(*args)
47
- newrelic_dispatcher_start
48
- begin
49
- dispatch_without_newrelic(*args)
50
- ensure
51
- newrelic_dispatcher_finish
52
- end
53
- end
54
-
55
- private
56
- # memoize the stats to avoid the cost of the lookup each time.
57
- def dispatch_stat
58
- NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'Rails/HTTP Dispatch'
59
- end
60
- def mongrel_queue_stat
61
- NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'WebFrontend/Mongrel/Average Queue Time'
62
- end
63
-
64
- # This won't work with Rails 2.2 multi-threading
65
- module BusyCalculator
66
- extend self
67
- # the fraction of the sample period that the dispatcher was busy
68
-
69
- @harvest_start = Time.now.to_f
70
- @accumulator = 0
71
- @entrypoint_stack = []
72
- @lock = Mutex.new
73
-
74
- def dispatcher_start(time)
75
- @lock.synchronize do
76
- @entrypoint_stack.push time
77
- end
78
- end
79
-
80
- def dispatcher_finish(time)
81
- @lock.synchronize do
82
- NewRelic::Control.instance.log.error("Stack underflow tracking dispatcher entry and exit!\n #{caller.join(" \n")}") and return if @entrypoint_stack.empty?
83
- @accumulator += (time - @entrypoint_stack.pop)
84
- end
85
- end
86
-
87
- def busy_count
88
- @entrypoint_stack.size
89
- end
90
-
91
- # Called before uploading to to the server to collect current busy stats.
92
- def harvest_busy
93
- busy = 0
94
- t0 = Time.now.to_f
95
- @lock.synchronize do
96
- busy = @accumulator
97
- @accumulator = 0
98
-
99
- # Walk through the stack and capture all times up to
100
- # now for entrypoints
101
- @entrypoint_stack.size.times do |frame|
102
- busy += (t0 - @entrypoint_stack[frame])
103
- @entrypoint_stack[frame] = t0
104
- end
105
-
106
- end
107
-
108
- busy = 0.0 if busy < 0.0 # don't go below 0%
109
-
110
- time_window = (t0 - @harvest_start)
111
- time_window = 1.0 if time_window == 0.0 # protect against divide by zero
112
-
113
- busy = busy / time_window
114
-
115
- instance_busy_stats.record_data_point busy unless busy == 0
116
- @harvest_start = t0
117
- end
118
- private
119
- def instance_busy_stats
120
- # Late binding on the Instance/busy stats
121
- NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'Instance/Busy'
122
- end
123
-
124
- end
125
-
126
- end
127
- end
@@ -1,14 +0,0 @@
1
- module NewRelic::Agent::Instrumentation
2
- module ErrorInstrumentation
3
- module Shim
4
- def newrelic_notice_error(*args); end
5
- end
6
- # Send the error instance to New Relic.
7
- # +metric_path+ is the optional metric identifier given for the context of the error.
8
- # +param_info+ is additional hash of info to be shown with the error.
9
- def newrelic_notice_error(exception, metric_path = nil, param_info = {})
10
- metric_path ||= self.newrelic_metric_path if self.respond_to? :newrelic_metric_path
11
- NewRelic::Agent.agent.error_collector.notice_error(exception, nil, metric_path, param_info)
12
- end
13
- end
14
- end
@@ -1,13 +0,0 @@
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
@@ -1,38 +0,0 @@
1
- require 'dispatcher'
2
- # NewRelic RPM instrumentation for http request dispatching (Routes mapping)
3
- # Note, the dispatcher class from no module into into the ActionController module
4
- # in Rails 2.0. Thus we need to check for both
5
- if defined? ActionController::Dispatcher
6
- target = ActionController::Dispatcher
7
- elsif defined? Dispatcher
8
- target = Dispatcher
9
- end
10
-
11
- # NOTE TODO: maybe this should be done with a middleware?
12
- if target
13
- require 'action_pack/version'
14
- NewRelic::Agent.instance.log.debug "Adding #{target} instrumentation"
15
-
16
- target.class_eval do
17
- if ActionPack::VERSION::MAJOR >= 2
18
- # In versions later that 1.* the dispatcher callbacks are used
19
- include NewRelic::Agent::Instrumentation::DispatcherInstrumentation
20
- before_dispatch :newrelic_dispatcher_start
21
- after_dispatch :newrelic_dispatcher_finish
22
- def newrelic_response_code
23
- (@response.headers['Status']||'200')[0..2] if ActionPack::VERSION::MAJOR == 2 && ActionPack::VERSION::MINOR < 3
24
- end
25
- else
26
- # In version 1.2.* the instrumentation is done by method chaining
27
- # the static dispatch method on the dispatcher class
28
- extend NewRelic::Agent::Instrumentation::DispatcherInstrumentation
29
- class << self
30
- alias_method :dispatch_without_newrelic, :dispatch
31
- alias_method :dispatch, :dispatch_newrelic
32
- def newrelic_response_code; end
33
- end
34
- end
35
- end
36
- else
37
- NewRelic::Agent.instance.log.debug "WARNING: Dispatcher instrumentation not added"
38
- end
@@ -1,125 +0,0 @@
1
- # This class is for debugging purposes only.
2
- # It inserts instrumentation into class loading to verify
3
- # that no classes are being loaded on the new relic thread,
4
- # which can cause problems in the class loader code.
5
- # It is only loaded by agent.rb when a particular newrelic.yml
6
- # option is set.
7
-
8
- module ClassLoadingWatcher # :nodoc: all
9
-
10
- extend self
11
- @@background_thread = nil
12
- @@flag_const_missing = nil
13
-
14
- def background_thread
15
- @@background_thread
16
- end
17
- def flag_const_missing
18
- @@flag_const_missing
19
- end
20
- def flag_const_missing=(val)
21
- @@flag_const_missing = val
22
- end
23
-
24
- def background_thread=(thread)
25
- @@background_thread = thread
26
-
27
- # these tests verify that check is working
28
- =begin
29
- @@background_thread = nil
30
- bad = ConstMissingInForegroundThread rescue nil
31
- @@background_thread = thread
32
- bad = ConstMissingInBackgroundThread rescue nil
33
- require 'new_relic/agent/patch_const_missing'
34
- load 'new_relic/agent/patch_const_missing.rb'
35
- =end
36
- end
37
- module SanityCheck
38
- def nr_check_for_classloading(*args)
39
-
40
- if Thread.current == ClassLoadingWatcher.background_thread
41
- nr_error "Agent background thread shouldn't be loading classes (#{args.inspect})"
42
- end
43
- end
44
- #
45
- def nr_check_for_constmissing(*args)
46
- if ClassLoadingWatcher.flag_const_missing
47
- nr_error "Classes in Agent should not be loaded via const_missing (#{args.inspect})"
48
- end
49
- end
50
- private
51
- def nr_error(msg)
52
- exception = NewRelic::Agent::BackgroundLoadingError.new(msg)
53
- backtrace = caller
54
- backtrace.shift
55
- exception.set_backtrace(backtrace)
56
- NewRelic::Agent.instance.error_collector.notice_error(exception, nil)
57
- msg << "\n" << backtrace.join("\n")
58
- NewRelic::Control.instance.log.error msg
59
- end
60
- end
61
- def enable_warning
62
- Object.class_eval do
63
- if !defined?(non_new_relic_require)
64
- alias_method :non_new_relic_require, :require
65
- alias_method :require, :new_relic_require
66
- end
67
-
68
- if !defined?(non_new_relic_load)
69
- alias_method :non_new_relic_load, :load
70
- alias_method :load, :new_relic_load
71
- end
72
- end
73
- Module.class_eval do
74
- if !defined?(non_new_relic_const_missing)
75
- alias_method :non_new_relic_const_missing, :const_missing
76
- alias_method :const_missing, :new_relic_const_missing
77
- end
78
- end
79
- end
80
-
81
- def disable_warning
82
- Object.class_eval do
83
- if defined?(non_new_relic_require)
84
- alias_method :require, :non_new_relic_require
85
- undef non_new_relic_require
86
- end
87
-
88
- if defined?(non_new_relic_load)
89
- alias_method :load, :non_new_relic_load
90
- undef non_new_relic_load
91
- end
92
- end
93
- Module.class_eval do
94
- if defined?(non_new_relic_const_missing)
95
- alias_method :const_missing, :non_new_relic_const_missing
96
- undef non_new_relic_const_missing
97
- end
98
- end
99
- end
100
- end
101
-
102
- class Object # :nodoc:
103
- include ClassLoadingWatcher::SanityCheck
104
-
105
- def new_relic_require(*args)
106
- nr_check_for_classloading("Object require", *args)
107
- non_new_relic_require(*args)
108
- end
109
-
110
- def new_relic_load(*args)
111
- nr_check_for_classloading("Object load", *args)
112
- non_new_relic_load(*args)
113
- end
114
- end
115
-
116
-
117
- class Module # :nodoc:
118
- include ClassLoadingWatcher::SanityCheck
119
-
120
- def new_relic_const_missing(*args)
121
- nr_check_for_constmissing("Module #{self.name} const_missing", *args)
122
- nr_check_for_classloading("Module #{self.name} const_missing", *args)
123
- non_new_relic_const_missing(*args)
124
- end
125
- end