ghazel-newrelic_rpm 3.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/CHANGELOG +525 -0
  2. data/LICENSE +37 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +423 -0
  14. data/lib/new_relic/agent/agent.rb +1040 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +61 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +83 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/error_collector.rb +203 -0
  20. data/lib/new_relic/agent/instrumentation.rb +9 -0
  21. data/lib/new_relic/agent/instrumentation/active_merchant.rb +21 -0
  22. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +62 -0
  23. data/lib/new_relic/agent/instrumentation/authlogic.rb +13 -0
  24. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +413 -0
  25. data/lib/new_relic/agent/instrumentation/data_mapper.rb +232 -0
  26. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +44 -0
  27. data/lib/new_relic/agent/instrumentation/memcache.rb +56 -0
  28. data/lib/new_relic/agent/instrumentation/merb/controller.rb +36 -0
  29. data/lib/new_relic/agent/instrumentation/merb/errors.rb +23 -0
  30. data/lib/new_relic/agent/instrumentation/metric_frame.rb +326 -0
  31. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +84 -0
  32. data/lib/new_relic/agent/instrumentation/net.rb +23 -0
  33. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +34 -0
  34. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  35. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +83 -0
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +36 -0
  38. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +108 -0
  39. data/lib/new_relic/agent/instrumentation/rails/errors.rb +36 -0
  40. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +60 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +112 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +31 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +54 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +23 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +16 -0
  46. data/lib/new_relic/agent/method_tracer.rb +422 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +144 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/stats_engine.rb +24 -0
  54. data/lib/new_relic/agent/stats_engine/metric_stats.rb +182 -0
  55. data/lib/new_relic/agent/stats_engine/samplers.rb +89 -0
  56. data/lib/new_relic/agent/stats_engine/transactions.rb +184 -0
  57. data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
  58. data/lib/new_relic/agent/transaction_sampler.rb +378 -0
  59. data/lib/new_relic/agent/worker_loop.rb +81 -0
  60. data/lib/new_relic/collection_helper.rb +69 -0
  61. data/lib/new_relic/command.rb +85 -0
  62. data/lib/new_relic/commands/deployments.rb +105 -0
  63. data/lib/new_relic/commands/install.rb +91 -0
  64. data/lib/new_relic/control.rb +48 -0
  65. data/lib/new_relic/control/class_methods.rb +47 -0
  66. data/lib/new_relic/control/configuration.rb +157 -0
  67. data/lib/new_relic/control/frameworks/external.rb +16 -0
  68. data/lib/new_relic/control/frameworks/merb.rb +30 -0
  69. data/lib/new_relic/control/frameworks/rails.rb +151 -0
  70. data/lib/new_relic/control/frameworks/rails3.rb +70 -0
  71. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  72. data/lib/new_relic/control/frameworks/sinatra.rb +23 -0
  73. data/lib/new_relic/control/instance_methods.rb +154 -0
  74. data/lib/new_relic/control/instrumentation.rb +81 -0
  75. data/lib/new_relic/control/logging_methods.rb +88 -0
  76. data/lib/new_relic/control/profiling.rb +25 -0
  77. data/lib/new_relic/control/server_methods.rb +104 -0
  78. data/lib/new_relic/data_serialization.rb +84 -0
  79. data/lib/new_relic/delayed_job_injection.rb +38 -0
  80. data/lib/new_relic/histogram.rb +91 -0
  81. data/lib/new_relic/local_environment.rb +391 -0
  82. data/lib/new_relic/merbtasks.rb +6 -0
  83. data/lib/new_relic/metric_data.rb +46 -0
  84. data/lib/new_relic/metric_spec.rb +73 -0
  85. data/lib/new_relic/metrics.rb +9 -0
  86. data/lib/new_relic/noticed_error.rb +24 -0
  87. data/lib/new_relic/rack/browser_monitoring.rb +68 -0
  88. data/lib/new_relic/rack/developer_mode.rb +267 -0
  89. data/lib/new_relic/rack/metric_app.rb +65 -0
  90. data/lib/new_relic/rack/mongrel_rpm.ru +28 -0
  91. data/lib/new_relic/rack/newrelic.yml +27 -0
  92. data/lib/new_relic/rack_app.rb +6 -0
  93. data/lib/new_relic/recipes.rb +73 -0
  94. data/lib/new_relic/stats.rb +378 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +76 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -0
  98. data/lib/new_relic/transaction_sample.rb +272 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +251 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +330 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/new_relic/agent/agent/connect_test.rb +316 -0
  116. data/test/new_relic/agent/agent/start_test.rb +340 -0
  117. data/test/new_relic/agent/agent/start_worker_thread_test.rb +155 -0
  118. data/test/new_relic/agent/agent_test.rb +173 -0
  119. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  120. data/test/new_relic/agent/agent_test_controller_test.rb +366 -0
  121. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  122. data/test/new_relic/agent/beacon_configuration_test.rb +104 -0
  123. data/test/new_relic/agent/browser_monitoring_test.rb +274 -0
  124. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  125. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  126. data/test/new_relic/agent/error_collector_test.rb +168 -0
  127. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +522 -0
  128. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
  129. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  130. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +179 -0
  131. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  132. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  133. data/test/new_relic/agent/instrumentation/queue_time_test.rb +387 -0
  134. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  135. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  136. data/test/new_relic/agent/memcache_instrumentation_test.rb +107 -0
  137. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  138. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  139. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  140. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  141. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  142. data/test/new_relic/agent/sampler_test.rb +19 -0
  143. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  144. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  145. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +81 -0
  146. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  147. data/test/new_relic/agent/stats_engine_test.rb +185 -0
  148. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  149. data/test/new_relic/agent/transaction_sampler_test.rb +945 -0
  150. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  151. data/test/new_relic/collection_helper_test.rb +127 -0
  152. data/test/new_relic/command/deployments_test.rb +68 -0
  153. data/test/new_relic/control/class_methods_test.rb +62 -0
  154. data/test/new_relic/control/logging_methods_test.rb +157 -0
  155. data/test/new_relic/control_test.rb +195 -0
  156. data/test/new_relic/data_serialization_test.rb +70 -0
  157. data/test/new_relic/local_environment_test.rb +72 -0
  158. data/test/new_relic/metric_data_test.rb +125 -0
  159. data/test/new_relic/metric_spec_test.rb +95 -0
  160. data/test/new_relic/rack/all_test.rb +11 -0
  161. data/test/new_relic/rack/browser_monitoring_test.rb +84 -0
  162. data/test/new_relic/rack/developer_mode_test.rb +43 -0
  163. data/test/new_relic/stats_test.rb +426 -0
  164. data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -0
  165. data/test/new_relic/transaction_analysis_test.rb +121 -0
  166. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  167. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  168. data/test/new_relic/transaction_sample/segment_test.rb +454 -0
  169. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  170. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  171. data/test/new_relic/transaction_sample_test.rb +170 -0
  172. data/test/new_relic/version_number_test.rb +89 -0
  173. data/test/test_contexts.rb +29 -0
  174. data/test/test_helper.rb +144 -0
  175. data/ui/helpers/developer_mode_helper.rb +351 -0
  176. data/ui/helpers/google_pie_chart.rb +49 -0
  177. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  178. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  179. data/ui/views/newrelic/_sample.rhtml +20 -0
  180. data/ui/views/newrelic/_segment.rhtml +28 -0
  181. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  182. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  183. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  184. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  185. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  186. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  187. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  188. data/ui/views/newrelic/_table.rhtml +12 -0
  189. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  190. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  191. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  192. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  193. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  194. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  195. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  196. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  197. data/ui/views/newrelic/file/images/textmate.png +0 -0
  198. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  199. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  200. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  201. data/ui/views/newrelic/index.rhtml +71 -0
  202. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  203. data/ui/views/newrelic/show_sample.rhtml +80 -0
  204. data/ui/views/newrelic/show_source.rhtml +3 -0
  205. data/ui/views/newrelic/threads.rhtml +53 -0
  206. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +19 -0
  207. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  208. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -0
  209. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  210. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  211. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
  212. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  213. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  214. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  215. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  216. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  217. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  218. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  219. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  220. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +122 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +66 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  255. metadata +399 -0
@@ -0,0 +1,65 @@
1
+ require 'fileutils'
2
+ module NewRelic
3
+ module Rack
4
+ class MetricApp
5
+ def initialize(options)
6
+ if options[:install]
7
+ src = File.join(File.dirname(__FILE__), "newrelic.yml")
8
+ require 'new_relic/command'
9
+ begin
10
+ NewRelic::Command::Install.new(:quiet => true, :src_file => src).run
11
+ NewRelic::Agent.logger.info "A newrelic.yml template was copied to #{File.expand_path('.')}."
12
+ NewRelic::Agent.logger.info "Please add a license key to the file and restart #{$0}"
13
+ exit 0
14
+ rescue NewRelic::Command::CommandFailure => e
15
+ NewRelic::Agent.logger.error e.message
16
+ exit 1
17
+ end
18
+ end
19
+ options[:app_name] ||= 'EPM Monitor'
20
+ options[:disable_samplers] = true
21
+ NewRelic::Agent.manual_start options
22
+ NewRelic::Agent.logger.warn "This rack app is deprecated - it will be removed in the next version of the Ruby Agent"
23
+ unless NewRelic::Control.instance.license_key
24
+ raise "Please add a valid license key to newrelic.yml."
25
+ end
26
+ end
27
+ def call(env)
28
+ request = ::Rack::Request.new env
29
+ params = request.params
30
+ if !(params['uri'] || params['metric'])
31
+ [400, { 'Content-Type' => 'text/plain' }, "Missing 'uri' or 'metric' parameter: #{params.inspect}" ]
32
+ elsif !params['value']
33
+ [400, { 'Content-Type' => 'text/plain' }, "Missing 'value' parameter: #{params.inspect}" ]
34
+ else
35
+ NewRelic::Agent.record_transaction( params['value'].to_f, params )
36
+ ::Rack::Response.new(params.collect { |k, v| "#{k}=#{v} " }.join).finish
37
+ end
38
+ end
39
+ end
40
+ class Status
41
+ def call(env)
42
+ request = ::Rack::Request.new env
43
+ data_url = "http://#{env['HTTP_HOST']}/metrics/path?value=nnn"
44
+ body = StringIO.new
45
+ body.puts "<html><body>"
46
+ body.puts "<h1>New Relic Actively Monitoring #{NewRelic::Control.instance.app_names.join(' and ')}</h1>"
47
+ body.puts "<p>To submit a metric value, use <a href='#{data_url}'>#{data_url}</a></p>"
48
+ body.puts "<h2>Request Details</h2>"
49
+ body.puts "<dl>"
50
+ body.puts "<dt>ip<dd>#{request.ip}"
51
+ body.puts "<dt>host<dd>#{request.host}"
52
+ body.puts "<dt>path<dd>#{request.url}"
53
+ body.puts "<dt>query<dd>#{request.query_string}"
54
+ body.puts "<dt>params<dd>#{request.params.inspect}"
55
+ body.puts "</dl>"
56
+ body.puts "<h2>Complete ENV</h2>"
57
+ body.puts "<ul>"
58
+ body.puts env.to_a.map{|k,v| "<li>#{k} = #{v}</li>" }.join("\n")
59
+ body.puts "</ul></body></html>"
60
+ response = ::Rack::Response.new body.string
61
+ response.finish
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ # This is so that we don't detect a dispatcher like mongrel and think we are
2
+ # monitoring it.
3
+ ENV['NEWRELIC_DISPATCHER'] = 'none'
4
+
5
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..','..'))
6
+
7
+ require 'new_relic/rack_app'
8
+
9
+ # Valid options which may be present in this binding:
10
+ # :license_key optional license key override
11
+ # :app_name optional name of app
12
+ # :logging optional, false to omit request logging to stdout
13
+
14
+ # use Rack::CommonLogger unless options[:logging] == false
15
+ # use Rack::ShowExceptions
16
+ # use Rack::Reloader if ENV['RACK_ENV'] == 'development'
17
+
18
+ puts "This Rack Metric Collection system is deprecated - it will be removed in the next version of the Ruby Agent"
19
+
20
+ map "/newrelic/record_value" do
21
+ run NewRelic::Rack::MetricApp.new(options)
22
+ end
23
+
24
+ map "/" do
25
+ run NewRelic::Rack::Status.new
26
+ end
27
+
28
+
@@ -0,0 +1,27 @@
1
+ #
2
+ # This file configures the Rack NewRelic Metric Application. Place a copy of this file
3
+ # in the directory where you start the mongrel_rpm process.
4
+ #
5
+ # <%= generated_for_user %>
6
+ #
7
+ common: &default_settings
8
+ log_level: info
9
+ enabled: true
10
+
11
+ # This is the key generated by script/create_admin
12
+ license_key: '<%= license_key %>'
13
+
14
+ # Replace this with the name of the application feeding
15
+ # metrics into the Metric application;
16
+ app_name: Application Monitor
17
+
18
+ # Set RACK_ENV to one of the following:
19
+
20
+ production:
21
+ <<: *default_settings
22
+ app_name: Production Monitor
23
+
24
+ staging:
25
+ <<: *default_settings
26
+ app_name: Staging Monitor
27
+
@@ -0,0 +1,6 @@
1
+ require 'rack/response'
2
+ require 'newrelic_rpm'
3
+
4
+ # Rack middlewares and applications used by New Relic
5
+ require 'new_relic/rack/metric_app'
6
+ require 'new_relic/rack/developer_mode'
@@ -0,0 +1,73 @@
1
+ # When installed as a plugin this is loaded automatically.
2
+ #
3
+ # When installed as a gem, you need to add
4
+ # require 'new_relic/recipes'
5
+ # to your deploy.rb
6
+ #
7
+ # Defined deploy:notify_rpm which will send information about the deploy to New Relic.
8
+ # The task will run on app servers except where no_release is true.
9
+ # If it fails, it will not affect the task execution or do a rollback.
10
+ #
11
+ make_notify_task = Proc.new do
12
+
13
+ namespace :newrelic do
14
+
15
+ # on all deployments, notify New Relic
16
+ desc "Record a deployment in New Relic (newrelic.com)"
17
+ task :notice_deployment, :roles => :app, :except => {:no_release => true } do
18
+ rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
19
+ require File.join(File.dirname(__FILE__), 'command.rb')
20
+ begin
21
+ # allow overrides to be defined for revision, description, changelog and appname
22
+ rev = fetch(:newrelic_revision) if exists?(:newrelic_revision)
23
+ description = fetch(:newrelic_desc) if exists?(:newrelic_desc)
24
+ changelog = fetch(:newrelic_changelog) if exists?(:newrelic_changelog)
25
+ appname = fetch(:newrelic_appname) if exists?(:newrelic_appname)
26
+ if !changelog
27
+ logger.debug "Getting log of changes for New Relic Deployment details"
28
+ from_revision = source.next_revision(current_revision)
29
+ if scm == :git
30
+ log_command = "git log --no-color --pretty=format:' * %an: %s' --abbrev-commit --no-merges #{previous_revision}..#{real_revision}"
31
+ else
32
+ log_command = "#{source.log(from_revision)}"
33
+ end
34
+ changelog = `#{log_command}`
35
+ end
36
+ new_revision = rev || source.query_revision(source.head()) do |cmd|
37
+ logger.debug "executing locally: '#{cmd}'"
38
+ `#{cmd}`
39
+ end
40
+ deploy_options = { :environment => rails_env,
41
+ :revision => new_revision,
42
+ :changelog => changelog,
43
+ :description => description,
44
+ :appname => appname }
45
+ logger.debug "Uploading deployment to New Relic"
46
+ deployment = NewRelic::Command::Deployments.new deploy_options
47
+ deployment.run
48
+ logger.info "Uploaded deployment information to New Relic"
49
+ rescue NewRelic::Command::CommandFailure => e
50
+ logger.info e.message
51
+ rescue Capistrano::CommandError
52
+ logger.info "Unable to notify New Relic of the deployment... skipping"
53
+ rescue Exception => e
54
+ logger.info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
55
+ end
56
+ # WIP: For rollbacks, let's update the deployment we created with an indication of the failure:
57
+ # on_rollback do
58
+ # run(...)
59
+ # end
60
+ end
61
+ end
62
+ end
63
+ require 'capistrano/version'
64
+ if defined?(Capistrano::Version::MAJOR) && Capistrano::Version::MAJOR < 2
65
+ STDERR.puts "Unable to load #{__FILE__}\nNew Relic Capistrano hooks require at least version 2.0.0"
66
+ else
67
+ instance = Capistrano::Configuration.instance
68
+ if instance
69
+ instance.load &make_notify_task
70
+ else
71
+ make_notify_task.call
72
+ end
73
+ end
@@ -0,0 +1,378 @@
1
+
2
+ module NewRelic
3
+ module Stats
4
+
5
+ def absent?
6
+ # guess on absent values
7
+ call_count == 0
8
+ end
9
+
10
+ def time_str(value_ms)
11
+ case
12
+ when value_ms >= 10000
13
+ "%.1f s" % (value_ms / 1000.0)
14
+ when value_ms >= 5000
15
+ "%.2f s" % (value_ms / 1000.0)
16
+ else
17
+ "%.0f ms" % value_ms
18
+ end
19
+ end
20
+
21
+ # makes sure we aren't dividing by zero
22
+ def checked_calculation(numerator, denominator)
23
+ if denominator.nil? || denominator == 0
24
+ 0.0
25
+ else
26
+ numerator.to_f / denominator
27
+ end
28
+ end
29
+
30
+ def average_call_time
31
+ checked_calculation(total_call_time, call_count)
32
+ end
33
+ def average_exclusive_time
34
+ checked_calculation(total_exclusive_time, call_count)
35
+ end
36
+
37
+ # merge by adding to average response time
38
+ # - used to compose multiple metrics e.g. dispatcher time + mongrel queue time
39
+ def sum_merge! (other_stats)
40
+ Array(other_stats).each do |other|
41
+ self.sum_attributes(other)
42
+ end
43
+ self
44
+ end
45
+
46
+ def sum_attributes(other)
47
+ update_totals(other)
48
+ stack_min_max_from(other)
49
+ update_boundaries(other)
50
+ end
51
+
52
+ def stack_min_max_from(other)
53
+ self.min_call_time += other.min_call_time
54
+ self.max_call_time += other.max_call_time
55
+ end
56
+
57
+ def update_boundaries(other)
58
+ self.begin_time = other.begin_time if should_replace_begin_time?(other)
59
+ self.end_time = other.end_time if should_replace_end_time?(other)
60
+ end
61
+
62
+ def should_replace_end_time?(other)
63
+ end_time.to_f < other.end_time.to_f
64
+ end
65
+
66
+ def should_replace_begin_time?(other)
67
+ other.begin_time.to_f < begin_time.to_f || begin_time.to_f == 0.0
68
+ end
69
+
70
+ def update_totals(other)
71
+ self.total_call_time += other.total_call_time
72
+ self.total_exclusive_time += other.total_exclusive_time
73
+ self.sum_of_squares += other.sum_of_squares
74
+ end
75
+
76
+ def min_time_less?(other)
77
+ (other.min_call_time < min_call_time && other.call_count > 0) || call_count == 0
78
+ end
79
+
80
+ def expand_min_max_to(other)
81
+ self.min_call_time = other.min_call_time if min_time_less?(other)
82
+ self.max_call_time = other.max_call_time if other.max_call_time > max_call_time
83
+ end
84
+
85
+ def merge_attributes(other)
86
+ update_totals(other)
87
+ expand_min_max_to(other)
88
+ self.call_count += other.call_count
89
+ update_boundaries(other)
90
+ end
91
+
92
+ def merge!(other_stats)
93
+ Array(other_stats).each do |other|
94
+ merge_attributes(other)
95
+ end
96
+
97
+ self
98
+ end
99
+
100
+ def merge(other_stats)
101
+ stats = self.clone
102
+ stats.merge!(other_stats)
103
+ end
104
+
105
+ # split into an array of timeslices whose
106
+ # time boundaries start on (begin_time + (n * duration)) and whose
107
+ # end time ends on (begin_time * (n + 1) * duration), except for the
108
+ # first and last elements, whose begin time and end time are the begin
109
+ # and end times of this stats instance, respectively. Yield to caller
110
+ # for the code that creates the actual stats instance
111
+ def split(rollup_begin_time, rollup_period)
112
+ rollup_begin_time = rollup_begin_time.to_f
113
+ rollup_begin_time += ((self.begin_time - rollup_begin_time) / rollup_period).floor * rollup_period
114
+
115
+ current_begin_time = self.begin_time
116
+ current_end_time = rollup_begin_time + rollup_period
117
+
118
+ return [self] if current_end_time >= self.end_time
119
+
120
+ timeslices = []
121
+ while current_end_time < self.end_time do
122
+ ts = yield(current_begin_time, current_end_time)
123
+ if ts
124
+ ts.fraction_of(self)
125
+ timeslices << ts
126
+ end
127
+ current_begin_time = current_end_time
128
+ current_end_time = current_begin_time + rollup_period
129
+ end
130
+
131
+ if self.end_time > current_begin_time
132
+ percentage = rollup_period / self.duration + (self.begin_time - rollup_begin_time) / rollup_period
133
+ ts = yield(current_begin_time, self.end_time)
134
+ if ts
135
+ ts.fraction_of(self)
136
+ timeslices << ts
137
+ end
138
+ end
139
+
140
+ timeslices
141
+ end
142
+
143
+ def is_reset?
144
+ call_count == 0 && total_call_time == 0.0 && total_exclusive_time == 0.0
145
+ end
146
+
147
+ def reset
148
+ self.call_count = 0
149
+ self.total_call_time = 0.0
150
+ self.total_exclusive_time = 0.0
151
+ self.min_call_time = 0.0
152
+ self.max_call_time = 0.0
153
+ self.sum_of_squares = 0.0
154
+ self.begin_time = Time.at(0)
155
+ self.end_time = Time.at(0)
156
+ end
157
+
158
+ def as_percentage_of(other_stats)
159
+ checked_calculation(total_call_time, other_stats.total_call_time) * 100.0
160
+ end
161
+
162
+ # the stat total_call_time is a percent
163
+ def as_percentage
164
+ average_call_time * 100.0
165
+ end
166
+
167
+ def duration
168
+ end_time ? (end_time - begin_time) : 0.0
169
+ end
170
+
171
+ def midpoint
172
+ begin_time + (duration/2)
173
+ end
174
+ def calls_per_minute
175
+ checked_calculation(call_count, duration) * 60
176
+ end
177
+
178
+ def total_call_time_per_minute
179
+ 60.0 * time_percentage
180
+ end
181
+
182
+ def standard_deviation
183
+ return 0 if call_count < 2 || self.sum_of_squares.nil?
184
+
185
+ # Convert sum of squares into standard deviation based on
186
+ # formula for the standard deviation for the entire population
187
+ x = self.sum_of_squares - (self.call_count * (self.average_value**2))
188
+ return 0 if x <= 0
189
+
190
+ Math.sqrt(x / self.call_count)
191
+ end
192
+
193
+ # returns the time spent in this component as a percentage of the total
194
+ # time window.
195
+ def time_percentage
196
+ checked_calculation(total_call_time, duration)
197
+ end
198
+
199
+ def exclusive_time_percentage
200
+ checked_calculation(total_exclusive_time, duration)
201
+ end
202
+
203
+ alias average_value average_call_time
204
+ alias average_response_time average_call_time
205
+ alias requests_per_minute calls_per_minute
206
+
207
+ def to_s
208
+ summary
209
+ end
210
+
211
+ # Summary string to facilitate testing
212
+ def summary
213
+ format = "%m/%d/%y %I:%M%p"
214
+ "[#{Time.at(begin_time.to_f).utc.strftime(format)} UTC, #{'%2.3fs' % duration.to_f}; #{'%2i' % call_count.to_i} calls #{'%4i' % average_call_time.to_f}s]"
215
+ end
216
+
217
+ # calculate this set of stats to be a percentage fraction
218
+ # of the provided stats, which has an overlapping time window.
219
+ # used as a key part of the split algorithm
220
+ def fraction_of(s)
221
+ min_end = (end_time < s.end_time ? end_time : s.end_time)
222
+ max_begin = (begin_time > s.begin_time ? begin_time : s.begin_time)
223
+ percentage = (min_end - max_begin) / s.duration
224
+
225
+ self.total_exclusive_time = s.total_exclusive_time * percentage
226
+ self.total_call_time = s.total_call_time * percentage
227
+ self.min_call_time = s.min_call_time
228
+ self.max_call_time = s.max_call_time
229
+ self.call_count = s.call_count * percentage
230
+ self.sum_of_squares = (s.sum_of_squares || 0) * percentage
231
+ end
232
+
233
+ # multiply the total time and rate by the given percentage
234
+ def multiply_by(percentage)
235
+ self.total_call_time = total_call_time * percentage
236
+ self.call_count = call_count * percentage
237
+ self.sum_of_squares = sum_of_squares * percentage
238
+
239
+ self
240
+ end
241
+
242
+ # returns s,t,f
243
+ def get_apdex
244
+ [@call_count, @total_call_time.to_i, @total_exclusive_time.to_i]
245
+ end
246
+
247
+ def apdex_score
248
+ s, t, f = get_apdex
249
+ (s.to_f + (t.to_f / 2)) / (s+t+f).to_f
250
+ end
251
+ end
252
+
253
+
254
+ class StatsBase
255
+ include Stats
256
+
257
+ attr_accessor :call_count
258
+ attr_accessor :min_call_time
259
+ attr_accessor :max_call_time
260
+ attr_accessor :total_call_time
261
+ attr_accessor :total_exclusive_time
262
+ attr_accessor :sum_of_squares
263
+
264
+ def initialize
265
+ reset
266
+ end
267
+
268
+ def freeze
269
+ @end_time = Time.now
270
+ super
271
+ end
272
+
273
+ def to_json(*a)
274
+ {'call_count' => call_count,
275
+ 'min_call_time' => min_call_time,
276
+ 'max_call_time' => max_call_time,
277
+ 'total_call_time' => total_call_time,
278
+ 'total_exclusive_time' => total_exclusive_time,
279
+ 'sum_of_squares' => sum_of_squares}.to_json(*a)
280
+ end
281
+
282
+
283
+ # In this class, we explicitly don't track begin and end time here, to save space during
284
+ # cross process serialization via xml. Still the accessor methods must be provided for merge to work.
285
+ def begin_time=(t)
286
+ end
287
+
288
+ def end_time=(t)
289
+ end
290
+
291
+ def begin_time
292
+ 0.0
293
+ end
294
+
295
+ def end_time
296
+ 0.0
297
+ end
298
+ end
299
+
300
+
301
+ class BasicStats < StatsBase
302
+ end
303
+
304
+ class ApdexStats < StatsBase
305
+
306
+ def record_apdex_s
307
+ @call_count += 1
308
+ end
309
+
310
+ def record_apdex_t
311
+ @total_call_time += 1
312
+ end
313
+
314
+ def record_apdex_f
315
+ @total_exclusive_time += 1
316
+ end
317
+ end
318
+
319
+ # Statistics used to track the performance of traced methods
320
+ class MethodTraceStats < StatsBase
321
+
322
+ alias data_point_count call_count
323
+
324
+ # record a single data point into the statistical gatherer. The gatherer
325
+ # will aggregate all data points collected over a specified period and upload
326
+ # its data to the NewRelic server
327
+ def record_data_point(value, exclusive_time = value)
328
+ @call_count += 1
329
+ @total_call_time += value
330
+ @min_call_time = value if value < @min_call_time || @call_count == 1
331
+ @max_call_time = value if value > @max_call_time
332
+ @total_exclusive_time += exclusive_time
333
+
334
+ @sum_of_squares += (value * value)
335
+ self
336
+ end
337
+
338
+ alias trace_call record_data_point
339
+
340
+ def record_multiple_data_points(total_value, count=1)
341
+ return record_data_point(total_value) if count == 1
342
+ @call_count += count
343
+ @total_call_time += total_value
344
+ avg_val = total_value / count
345
+ @min_call_time = avg_val if avg_val < @min_call_time || @call_count == count
346
+ @max_call_time = avg_val if avg_val > @max_call_time
347
+ @total_exclusive_time += total_value
348
+ @sum_of_squares += (avg_val * avg_val) * count
349
+ self
350
+ end
351
+
352
+ def increment_count(value = 1)
353
+ @call_count += value
354
+ end
355
+
356
+ def inspect
357
+ "#<NewRelic::MethodTraceStats #{summary} >"
358
+ end
359
+
360
+ end
361
+
362
+ class ScopedMethodTraceStats < MethodTraceStats
363
+ attr_accessor :unscoped_stats
364
+ def initialize(unscoped_stats)
365
+ super()
366
+ self.unscoped_stats = unscoped_stats
367
+ end
368
+ def trace_call(call_time, exclusive_time = call_time)
369
+ unscoped_stats.trace_call call_time, exclusive_time
370
+ super call_time, exclusive_time
371
+ end
372
+ def record_multiple_data_points(total_value, count=1)
373
+ unscoped_stats.record_multiple_data_points(total_value, count)
374
+ super total_value, count
375
+ end
376
+ end
377
+ end
378
+