dolores_rpm 3.2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. data/CHANGELOG +559 -0
  2. data/LICENSE +64 -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/dolores_rpm-3.3.4.fork.gem +0 -0
  11. data/install.rb +9 -0
  12. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  13. data/lib/conditional_vendored_metric_parser.rb +5 -0
  14. data/lib/new_relic/agent/agent.rb +1311 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +110 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +102 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +203 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation/active_merchant.rb +27 -0
  22. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  23. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  24. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +424 -0
  25. data/lib/new_relic/agent/instrumentation/data_mapper.rb +57 -0
  26. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  27. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  28. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  29. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  30. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  31. data/lib/new_relic/agent/instrumentation/metric_frame.rb +332 -0
  32. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  33. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +36 -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 +114 -0
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  38. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +115 -0
  39. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +118 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +122 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +58 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/instrumentation.rb +9 -0
  47. data/lib/new_relic/agent/method_tracer.rb +528 -0
  48. data/lib/new_relic/agent/sampler.rb +50 -0
  49. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  50. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  51. data/lib/new_relic/agent/samplers/memory_sampler.rb +144 -0
  52. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  53. data/lib/new_relic/agent/shim_agent.rb +29 -0
  54. data/lib/new_relic/agent/sql_sampler.rb +267 -0
  55. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  56. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  57. data/lib/new_relic/agent/stats_engine/transactions.rb +208 -0
  58. data/lib/new_relic/agent/stats_engine.rb +25 -0
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
  60. data/lib/new_relic/agent/transaction_sampler.rb +397 -0
  61. data/lib/new_relic/agent/worker_loop.rb +89 -0
  62. data/lib/new_relic/agent.rb +454 -0
  63. data/lib/new_relic/collection_helper.rb +75 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control/class_methods.rb +53 -0
  68. data/lib/new_relic/control/configuration.rb +202 -0
  69. data/lib/new_relic/control/frameworks/external.rb +16 -0
  70. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  71. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  72. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  73. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  74. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  75. data/lib/new_relic/control/frameworks.rb +10 -0
  76. data/lib/new_relic/control/instance_methods.rb +179 -0
  77. data/lib/new_relic/control/instrumentation.rb +100 -0
  78. data/lib/new_relic/control/logging_methods.rb +143 -0
  79. data/lib/new_relic/control/profiling.rb +25 -0
  80. data/lib/new_relic/control/server_methods.rb +114 -0
  81. data/lib/new_relic/control.rb +46 -0
  82. data/lib/new_relic/data_serialization.rb +157 -0
  83. data/lib/new_relic/delayed_job_injection.rb +46 -0
  84. data/lib/new_relic/language_support.rb +69 -0
  85. data/lib/new_relic/local_environment.rb +414 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +75 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +24 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +68 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +73 -0
  94. data/lib/new_relic/stats.rb +388 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  97. data/lib/new_relic/transaction_analysis.rb +77 -0
  98. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  99. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  100. data/lib/new_relic/transaction_sample/segment.rb +201 -0
  101. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  102. data/lib/new_relic/transaction_sample.rb +245 -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/recipes/newrelic.rb +6 -0
  111. data/test/active_record_fixtures.rb +77 -0
  112. data/test/config/newrelic.yml +48 -0
  113. data/test/config/test_control.rb +48 -0
  114. data/test/new_relic/agent/agent/connect_test.rb +410 -0
  115. data/test/new_relic/agent/agent/start_test.rb +255 -0
  116. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  117. data/test/new_relic/agent/agent_test.rb +139 -0
  118. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  119. data/test/new_relic/agent/agent_test_controller_test.rb +363 -0
  120. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  121. data/test/new_relic/agent/beacon_configuration_test.rb +108 -0
  122. data/test/new_relic/agent/browser_monitoring_test.rb +278 -0
  123. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  124. data/test/new_relic/agent/database_test.rb +162 -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 +175 -0
  127. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +538 -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 +172 -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 +143 -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/sql_sampler_test.rb +160 -0
  145. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  146. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  147. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  148. data/test/new_relic/agent/stats_engine_test.rb +185 -0
  149. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  150. data/test/new_relic/agent/transaction_sampler_test.rb +955 -0
  151. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  152. data/test/new_relic/agent_test.rb +175 -0
  153. data/test/new_relic/collection_helper_test.rb +149 -0
  154. data/test/new_relic/command/deployments_test.rb +68 -0
  155. data/test/new_relic/control/class_methods_test.rb +62 -0
  156. data/test/new_relic/control/configuration_test.rb +72 -0
  157. data/test/new_relic/control/logging_methods_test.rb +185 -0
  158. data/test/new_relic/control_test.rb +254 -0
  159. data/test/new_relic/data_serialization_test.rb +208 -0
  160. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  161. data/test/new_relic/local_environment_test.rb +72 -0
  162. data/test/new_relic/metric_data_test.rb +125 -0
  163. data/test/new_relic/metric_spec_test.rb +95 -0
  164. data/test/new_relic/rack/all_test.rb +11 -0
  165. data/test/new_relic/rack/browser_monitoring_test.rb +84 -0
  166. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  167. data/test/new_relic/rack/developer_mode_test.rb +43 -0
  168. data/test/new_relic/stats_test.rb +426 -0
  169. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  170. data/test/new_relic/transaction_analysis_test.rb +121 -0
  171. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  172. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  173. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  174. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  175. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  176. data/test/new_relic/transaction_sample_test.rb +164 -0
  177. data/test/new_relic/version_number_test.rb +89 -0
  178. data/test/test_contexts.rb +29 -0
  179. data/test/test_helper.rb +154 -0
  180. data/ui/helpers/developer_mode_helper.rb +357 -0
  181. data/ui/helpers/google_pie_chart.rb +48 -0
  182. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  183. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  184. data/ui/views/newrelic/_sample.rhtml +20 -0
  185. data/ui/views/newrelic/_segment.rhtml +28 -0
  186. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  187. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  188. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  189. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  190. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  191. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  192. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  193. data/ui/views/newrelic/_table.rhtml +12 -0
  194. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  195. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  196. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  197. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  198. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  199. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  200. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  201. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  202. data/ui/views/newrelic/file/images/textmate.png +0 -0
  203. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  204. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  205. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  206. data/ui/views/newrelic/index.rhtml +71 -0
  207. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  208. data/ui/views/newrelic/show_sample.rhtml +80 -0
  209. data/ui/views/newrelic/show_source.rhtml +3 -0
  210. data/ui/views/newrelic/threads.rhtml +53 -0
  211. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  212. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  213. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +62 -0
  214. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  215. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  216. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  217. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  218. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  219. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  220. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +122 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  257. metadata +398 -0
@@ -0,0 +1,105 @@
1
+ # This is a class for executing commands related to deployment
2
+ # events. It runs without loading the rails environment
3
+
4
+ require 'yaml'
5
+ require 'net/http'
6
+ require 'rexml/document'
7
+
8
+ # We need to use the Control object but we don't want to load
9
+ # the rails/merb environment. The defined? clause is so that
10
+ # it won't load it twice, something it does when run inside a test
11
+ require 'new_relic/control' unless defined? NewRelic::Control
12
+
13
+ class NewRelic::Command::Deployments < NewRelic::Command
14
+ attr_reader :config
15
+ def self.command; "deployments"; end
16
+
17
+ # Initialize the deployment uploader with command line args.
18
+ # Use -h to see options.
19
+ # When command_line_args is a hash, we are invoking directly and
20
+ # it's treated as an options with optional string values for
21
+ # :user, :description, :appname, :revision, :environment,
22
+ # and :changes.
23
+ #
24
+ # Will throw CommandFailed exception if there's any error.
25
+ #
26
+ def initialize command_line_args
27
+ @config = NewRelic::Control.instance
28
+ super(command_line_args)
29
+ @description ||= @leftover && @leftover.join(" ")
30
+ @user ||= ENV['USER']
31
+ config.env = @environment if @environment
32
+ @appname ||= config.app_names[0] || config.env || 'development'
33
+ end
34
+
35
+ # Run the Deployment upload in New Relic via Active Resource.
36
+ # Will possibly print errors and exit the VM
37
+ def run
38
+ begin
39
+ @description = nil if @description && @description.strip.empty?
40
+ create_params = {}
41
+ {
42
+ :application_id => @appname,
43
+ :host => Socket.gethostname,
44
+ :description => @description,
45
+ :user => @user,
46
+ :revision => @revision,
47
+ :changelog => @changelog
48
+ }.each do |k, v|
49
+ create_params["deployment[#{k}]"] = v unless v.nil? || v == ''
50
+ end
51
+ http = config.http_connection(config.api_server)
52
+
53
+ uri = "/deployments.xml"
54
+
55
+ raise "license_key was not set in newrelic.yml for #{config.env}" if config['license_key'].nil?
56
+ request = Net::HTTP::Post.new(uri, {'x-license-key' => config['license_key']})
57
+ request.content_type = "application/octet-stream"
58
+
59
+ request.set_form_data(create_params)
60
+
61
+ response = http.request(request)
62
+
63
+ if response.is_a? Net::HTTPSuccess
64
+ info "Recorded deployment to '#{@appname}' (#{@description || Time.now })"
65
+ else
66
+ err_string = REXML::Document.new(response.body).elements['errors/error'].map(&:to_s).join("; ") rescue response.message
67
+ raise NewRelic::Command::CommandFailure, "Deployment not recorded: #{err_string}"
68
+ end
69
+ rescue SystemCallError, SocketError => e
70
+ # These include Errno connection errors
71
+ err_string = "Transient error attempting to connect to #{config.api_server} (#{e})"
72
+ raise NewRelic::Command::CommandFailure.new(err_string)
73
+ rescue NewRelic::Command::CommandFailure
74
+ raise
75
+ rescue Exception => e
76
+ err "Unexpected error attempting to connect to #{config.api_server}"
77
+ info "#{e}: #{e.backtrace.join("\n ")}"
78
+ raise NewRelic::Command::CommandFailure.new(e.to_s)
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def options
85
+ OptionParser.new %Q{Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] }, 40 do |o|
86
+ o.separator "OPTIONS:"
87
+ o.on("-a", "--appname=NAME", String,
88
+ "Set the application name.",
89
+ "Default is app_name setting in newrelic.yml") { | e | @appname = e }
90
+ o.on("-e", "--environment=name", String,
91
+ "Override the (RAILS|MERB|RUBY|RACK)_ENV setting",
92
+ "currently: #{config.env}") { | e | @environment = e }
93
+ o.on("-u", "--user=USER", String,
94
+ "Specify the user deploying, for information only",
95
+ "Default: #{@user || '<none>'}") { | u | @user = u }
96
+ o.on("-r", "--revision=REV", String,
97
+ "Specify the revision being deployed") { | r | @revision = r }
98
+ o.on("-c", "--changes",
99
+ "Read in a change log from the standard input") { @changelog = STDIN.read }
100
+ yield o if block_given?
101
+ end
102
+ end
103
+
104
+
105
+ end
@@ -0,0 +1,80 @@
1
+ require 'fileutils'
2
+ require 'new_relic/version'
3
+ require 'erb'
4
+
5
+ class NewRelic::Command::Install < NewRelic::Command
6
+
7
+ NO_LICENSE_KEY = "<PASTE LICENSE KEY HERE>"
8
+
9
+ def self.command; "install"; end
10
+
11
+ # Use -h to see options.
12
+ # When command_line_args is a hash, we are invoking directly and
13
+ # it's treated as an options with optional string values for
14
+ # :user, :description, :appname, :revision, :environment,
15
+ # and :changes.
16
+ #
17
+ # Will throw CommandFailed exception if there's any error.
18
+ #
19
+ attr_reader :dest_dir, :license_key, :generated_for_user, :quiet, :src_file, :app_name
20
+ def initialize command_line_args={}
21
+ super command_line_args
22
+ if !@dest_dir
23
+ # Install a newrelic.yml file into the local config directory.
24
+ if File.directory? "config"
25
+ @dest_dir = "config"
26
+ else
27
+ @dest_dir = "."
28
+ end
29
+ end
30
+ @license_key ||= NO_LICENSE_KEY
31
+ @app_name ||= @leftover
32
+ raise CommandFailure.new("Application name required.", @options) unless @app_name && @app_name.size > 0
33
+ @generated_for_user ||= @user_string || ""
34
+ end
35
+
36
+ def run
37
+ dest_file = File.expand_path(@dest_dir + "/newrelic.yml")
38
+ if File.exist?(dest_file)
39
+ raise NewRelic::Command::CommandFailure, "newrelic.yml file already exists. Move it out of the way."
40
+ end
41
+ File.open(dest_file, 'w') { | out | out.puts(content) }
42
+
43
+ puts <<-EOF unless quiet
44
+
45
+ Installed a default configuration file at
46
+ #{dest_file}.
47
+ EOF
48
+ puts <<-EOF unless quiet || @license_key != NO_LICENSE_KEY
49
+
50
+ To monitor your application in production mode, sign up for an account
51
+ at www.newrelic.com, and replace the newrelic.yml file with the one
52
+ you receive upon registration.
53
+ EOF
54
+ puts <<-EOF unless quiet
55
+
56
+ E-mail support@newrelic.com with any problems or questions.
57
+ EOF
58
+
59
+ end
60
+
61
+ def content
62
+ @src_file ||= File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","newrelic.yml"))
63
+ template = File.read(@src_file)
64
+ ERB.new(template).result(binding)
65
+ end
66
+
67
+ private
68
+
69
+ def options
70
+ OptionParser.new "Usage: #{$0} #{self.class.command} [ OPTIONS] 'application name'", 40 do |o|
71
+ o.on("-l", "--license_key=NAME", String,
72
+ "Use the given license key") { | e | @license_key = e }
73
+ o.on("-d", "--destdir=name", String,
74
+ "Write the newrelic.yml to the given directory, default is '.'") { | e | @dest_dir = e }
75
+ yield o if block_given?
76
+ end
77
+ end
78
+
79
+
80
+ end
@@ -0,0 +1,53 @@
1
+ module NewRelic
2
+ class Control
3
+ # class-level methods for lazy creation of NewRelic::Control and
4
+ # NewRelic::LocalEnvironment instances.
5
+ module ClassMethods
6
+ # Access the Control singleton, lazy initialized. Default will instantiate a new
7
+ # instance or pass false to defer
8
+ def instance(create=true)
9
+ @instance ||= create && new_instance
10
+ end
11
+
12
+ # Access the LocalEnvironment singleton, lazy initialized
13
+ def local_env
14
+ @local_env ||= NewRelic::LocalEnvironment.new
15
+ end
16
+
17
+ # Create the concrete class for environment specific behavior
18
+ def new_instance
19
+ if local_env.framework == :test
20
+ load_test_framework
21
+ else
22
+ load_framework_class(local_env.framework).new(local_env)
23
+ end
24
+ end
25
+
26
+ # nb this does not 'load test' the framework, it loads the 'test framework'
27
+ def load_test_framework
28
+ config = File.expand_path(File.join('..','..','..','..', "test","config","newrelic.yml"), __FILE__)
29
+ require "config/test_control"
30
+ NewRelic::Control::Frameworks::Test.new(local_env, config)
31
+ end
32
+
33
+ # Loads the specified framework class from the
34
+ # NewRelic::Control::Frameworks module
35
+ def load_framework_class(framework)
36
+ begin
37
+ require "new_relic/control/frameworks/#{framework}"
38
+ rescue LoadError
39
+ # maybe it is already loaded by some external system
40
+ # i.e. rpm_contrib or user extensions?
41
+ end
42
+ NewRelic::Control::Frameworks.const_get(framework.to_s.capitalize)
43
+ end
44
+
45
+ # The root directory for the plugin or gem
46
+ def newrelic_root
47
+ File.expand_path(File.join("..", "..", "..", ".."), __FILE__)
48
+ end
49
+ end
50
+ extend ClassMethods
51
+ end
52
+ end
53
+
@@ -0,0 +1,202 @@
1
+ module NewRelic
2
+ class Control
3
+ # used to contain methods to look up settings from the
4
+ # configuration located in newrelic.yml
5
+ module Configuration
6
+ def settings
7
+ unless @settings
8
+ @settings = (@yaml && merge_defaults(@yaml[env])) || {}
9
+ # At the time we bind the settings, we also need to run this little piece
10
+ # of magic which allows someone to augment the id with the app name, necessary
11
+ if self['multi_homed'] && app_names.size > 0
12
+ if @local_env.dispatcher_instance_id
13
+ @local_env.dispatcher_instance_id << ":#{app_names.first}"
14
+ else
15
+ @local_env.dispatcher_instance_id = app_names.first
16
+ end
17
+ end
18
+
19
+ end
20
+ @settings
21
+ end
22
+
23
+ def merge_defaults(settings_hash)
24
+ s = {
25
+ 'host' => 'collector.newrelic.com',
26
+ 'ssl' => false,
27
+ 'log_level' => 'info',
28
+ 'apdex_t' => 0.5
29
+ }
30
+ s.merge! settings_hash if settings_hash
31
+ # monitor_daemons replaced with agent_enabled
32
+ s['agent_enabled'] = s.delete('monitor_daemons') if s['agent_enabled'].nil? && s.include?('monitor_daemons')
33
+ s
34
+ end
35
+
36
+ # Merge the given options into the config options.
37
+ # They might be a nested hash
38
+ def merge_options(options, hash=self)
39
+ options.each do |key, val|
40
+ case
41
+ when key == :config then next
42
+ when val.is_a?(Hash)
43
+ merge_options(val, hash[key.to_s] ||= {})
44
+ when val.nil?
45
+ hash.delete(key.to_s)
46
+ else
47
+ hash[key.to_s] = val
48
+ end
49
+ end
50
+ end
51
+
52
+ def merge_server_side_config(data)
53
+ remove_server_controlled_configs
54
+ config = Hash.new
55
+ data.each_pair do |key, value|
56
+ if key.include?('.')
57
+ key = key.split('.')
58
+ config[key.first] ||= Hash.new
59
+ config[key.first][key[1]] = value
60
+ else
61
+ config[key] = value
62
+ end
63
+ end
64
+ merge_options(config)
65
+ end
66
+
67
+ def remove_server_controlled_configs
68
+ settings.delete('transaction_tracer')
69
+ settings.delete('slow_sql')
70
+ settings.delete('error_collector')
71
+ settings.delete('capture_params')
72
+ end
73
+
74
+ def [](key)
75
+ fetch(key)
76
+ end
77
+
78
+ def []=(key, value)
79
+ settings[key] = value
80
+ end
81
+
82
+ def fetch(key, default=nil)
83
+ settings.fetch(key, default)
84
+ end
85
+
86
+ def apdex_t
87
+ # Always initialized with a default
88
+ fetch('apdex_t').to_f
89
+ end
90
+
91
+ def license_key
92
+ env_setting = ENV['NEW_RELIC_LICENSE_KEY'] || ENV['NEWRELIC_LICENSE_KEY']
93
+ fetch('license_key', env_setting)
94
+ end
95
+
96
+ def capture_params
97
+ fetch('capture_params')
98
+ end
99
+
100
+ # True if we are sending data to the server, monitoring production
101
+ def monitor_mode?
102
+ fetch('monitor_mode', fetch('enabled'))
103
+ end
104
+
105
+ # True if we are capturing data and displaying in /newrelic
106
+ def developer_mode?
107
+ fetch('developer_mode', fetch('developer'))
108
+ end
109
+
110
+ # whether we should install the
111
+ # NewRelic::Rack::BrowserMonitoring middleware automatically on
112
+ # Rails applications
113
+ def browser_monitoring_auto_instrument?
114
+ fetch('browser_monitoring', {}).fetch('auto_instrument', true)
115
+ end
116
+
117
+ def multi_threaded?
118
+ fetch('multi_threaded')
119
+ end
120
+
121
+ def disable_serialization?
122
+ fetch('disable_serialization', false)
123
+ end
124
+ def disable_serialization=(b)
125
+ self['disable_serialization'] = b
126
+ end
127
+
128
+ # True if we should view files in textmate
129
+ def use_textmate?
130
+ fetch('textmate')
131
+ end
132
+
133
+ # defaults to 2MiB
134
+ def post_size_limit
135
+ fetch('post_size_limit', 2 * 1024 * 1024)
136
+ end
137
+
138
+ # Configuration option of the same name to indicate that we should connect
139
+ # to New Relic synchronously on startup. This means when the agent is loaded it
140
+ # won't return without trying to set up the server connection at least once
141
+ # which can make startup take longer. Defaults to false.
142
+ def sync_startup
143
+ fetch('sync_startup', false)
144
+ end
145
+
146
+ # Configuration option of the same name to indicate that we should flush
147
+ # data to the server on exiting. Defaults to true.
148
+ def send_data_on_exit
149
+ fetch('send_data_on_exit', true)
150
+ end
151
+
152
+ def dispatcher_instance_id
153
+ self['dispatcher_instance_id'] || @local_env.dispatcher_instance_id
154
+ end
155
+
156
+ def dispatcher
157
+ (self['dispatcher'] && self['dispatcher'].to_sym) || @local_env.dispatcher
158
+ end
159
+ def app_names
160
+ case self['app_name']
161
+ when Array then self['app_name']
162
+ when String then self['app_name'].split(';')
163
+ else [ env ]
164
+ end
165
+ end
166
+ def validate_seed
167
+ self['validate_seed'] || ENV['NR_VALIDATE_SEED']
168
+ end
169
+ def validate_token
170
+ self['validate_token'] || ENV['NR_VALIDATE_TOKEN']
171
+ end
172
+
173
+ def use_ssl?
174
+ @use_ssl = fetch('ssl', false) unless @use_ssl
175
+ @use_ssl
176
+ end
177
+
178
+ def log_file_path
179
+ fetch('log_file_path', 'log/')
180
+ end
181
+
182
+ # only verify certificates if you're very sure you want this
183
+ # level of security, it includes possibly app-crashing dns
184
+ # lookups every connection to the server
185
+ def verify_certificate?
186
+ unless @verify_certificate
187
+ unless use_ssl?
188
+ @verify_certificate = false
189
+ else
190
+ @verify_certificate = fetch('verify_certificate', false)
191
+ end
192
+ end
193
+ @verify_certificate
194
+ end
195
+
196
+ def disable_backtrace_cleanup?
197
+ fetch('disable_backtrace_cleanup')
198
+ end
199
+ end
200
+ include Configuration
201
+ end
202
+ end
@@ -0,0 +1,16 @@
1
+ require 'new_relic/control/frameworks/ruby'
2
+ module NewRelic
3
+ class Control
4
+ module Frameworks
5
+ # This is the control used when starting up in the context of
6
+ # The New Relic Infrastructure Agent. We want to call this
7
+ # out specifically because in this context we are not monitoring
8
+ # the running process, but actually external things.
9
+ class External < NewRelic::Control::Frameworks::Ruby
10
+ def init_config(options={})
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ module NewRelic
2
+ class Control
3
+ module Frameworks
4
+ # Includes limited support for Merb
5
+ class Merb < NewRelic::Control
6
+
7
+ def env
8
+ @env ||= ::Merb.env
9
+ end
10
+ def root
11
+ ::Merb.root
12
+ end
13
+
14
+ def to_stdout(msg)
15
+ Merb.logger.info("NewRelic ~ " + msg)
16
+ rescue Exception => e
17
+ STDOUT.puts "NewRelic ~ " + msg
18
+ end
19
+
20
+ def init_config options={}
21
+ ::Merb::Plugins.add_rakefiles File.join(newrelic_root,"lib/tasks/all.rb")
22
+
23
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
24
+ ::Merb::Plugins.config[:newrelic] = {
25
+ :config => self
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,164 @@
1
+ require 'new_relic/control/frameworks/ruby'
2
+ module NewRelic
3
+ class Control
4
+ module Frameworks
5
+ # Control subclass instantiated when Rails is detected. Contains
6
+ # Rails specific configuration, instrumentation, environment values,
7
+ # etc.
8
+ class Rails < NewRelic::Control::Frameworks::Ruby
9
+
10
+ def env
11
+ @env ||= RAILS_ENV.dup
12
+ end
13
+ def root
14
+ if defined?(RAILS_ROOT) && RAILS_ROOT.to_s != ''
15
+ RAILS_ROOT.to_s
16
+ else
17
+ super
18
+ end
19
+ end
20
+ def logger
21
+ ::RAILS_DEFAULT_LOGGER
22
+ end
23
+
24
+ # In versions of Rails prior to 2.0, the rails config was only available to
25
+ # the init.rb, so it had to be passed on from there. This is a best effort to
26
+ # find a config and use that.
27
+ def init_config(options={})
28
+ rails_config = options[:config]
29
+ if !rails_config && defined?(::Rails) && ::Rails.respond_to?(:configuration)
30
+ rails_config = ::Rails.configuration
31
+ end
32
+ # Install the dependency detection,
33
+ if rails_config && ::Rails.configuration.respond_to?(:after_initialize)
34
+ rails_config.after_initialize do
35
+ # This will insure we load all the instrumentation as late as possible. If the agent
36
+ # is not enabled, it will load a limited amount of instrumentation. See
37
+ # delayed_job_injection.rb
38
+ DependencyDetection.detect!
39
+ end
40
+ end
41
+ if !agent_enabled?
42
+ # Might not be running if it does not think mongrel, thin, passenger, etc
43
+ # is running, if it things it's a rake task, or if the agent_enabled is false.
44
+ log! "New Relic Agent not running."
45
+ else
46
+ log! "Starting the New Relic Agent."
47
+ install_developer_mode rails_config if developer_mode?
48
+ install_browser_monitoring(rails_config)
49
+ end
50
+ end
51
+
52
+ def install_browser_monitoring(config)
53
+ return if @browser_monitoring_installed
54
+ @browser_monitoring_installed = true
55
+ return if config.nil? || !config.respond_to?(:middleware) || !browser_monitoring_auto_instrument?
56
+ begin
57
+ require 'new_relic/rack/browser_monitoring'
58
+ config.middleware.use NewRelic::Rack::BrowserMonitoring
59
+ log!("Installed New Relic Browser Monitoring middleware", :info)
60
+ rescue Exception => e
61
+ log!("Error installing New Relic Browser Monitoring middleware: #{e.inspect}", :error)
62
+ end
63
+ end
64
+
65
+ def install_developer_mode(rails_config)
66
+ return if @installed
67
+ @installed = true
68
+ if rails_config && rails_config.respond_to?(:middleware)
69
+ begin
70
+ require 'new_relic/rack/developer_mode'
71
+ rails_config.middleware.use NewRelic::Rack::DeveloperMode
72
+
73
+ # inform user that the dev edition is available if we are running inside
74
+ # a webserver process
75
+ if @local_env.dispatcher_instance_id
76
+ port = @local_env.dispatcher_instance_id.to_s =~ /^\d+/ ? ":#{local_env.dispatcher_instance_id}" : ":port"
77
+ log!("NewRelic Agent Developer Mode enabled.")
78
+ log!("To view performance information, go to http://localhost#{port}/newrelic")
79
+ end
80
+ rescue Exception => e
81
+ log!("Error installing New Relic Developer Mode: #{e.inspect}", :error)
82
+ end
83
+ elsif rails_config
84
+ log!("Developer mode not available for Rails versions prior to 2.2", :warn)
85
+ end
86
+ end
87
+
88
+ def log!(msg, level=:info)
89
+ if should_log?
90
+ logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
91
+ logger.send(level, msg)
92
+ else
93
+ super
94
+ end
95
+ rescue Exception => e
96
+ super
97
+ end
98
+
99
+ def to_stdout(message)
100
+ logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
101
+ logger.info(message)
102
+ rescue Exception => e
103
+ super
104
+ end
105
+
106
+ def rails_version
107
+ @rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
108
+ end
109
+
110
+ protected
111
+
112
+ def rails_vendor_root
113
+ File.join(root,'vendor','rails')
114
+ end
115
+
116
+ def rails_gem_list
117
+ ::Rails.configuration.gems.map do | gem |
118
+ version = (gem.respond_to?(:version) && gem.version) ||
119
+ (gem.specification.respond_to?(:version) && gem.specification.version)
120
+ gem.name + (version ? "(#{version})" : "")
121
+ end
122
+ end
123
+
124
+ # Collect the Rails::Info into an associative array as well as the list of plugins
125
+ def append_environment_info
126
+ local_env.append_environment_value('Rails version'){ ::Rails::VERSION::STRING }
127
+ if rails_version >= NewRelic::VersionNumber.new('2.2.0')
128
+ local_env.append_environment_value('Rails threadsafe') do
129
+ ::Rails.configuration.action_controller.allow_concurrency == true
130
+ end
131
+ end
132
+ local_env.append_environment_value('Rails Env') { ENV['RAILS_ENV'] }
133
+ if rails_version >= NewRelic::VersionNumber.new('2.1.0')
134
+ local_env.append_gem_list do
135
+ (bundler_gem_list + rails_gem_list).uniq
136
+ end
137
+ # The plugins is configured manually. If it's nil, it loads everything non-deterministically
138
+ if ::Rails.configuration.plugins
139
+ local_env.append_plugin_list { ::Rails.configuration.plugins }
140
+ else
141
+ ::Rails.configuration.plugin_paths.each do |path|
142
+ local_env.append_plugin_list { Dir[File.join(path, '*')].collect{ |p| File.basename p if File.directory? p }.compact }
143
+ end
144
+ end
145
+ else
146
+ # Rails prior to 2.1, can't get the gems. Find plugins in the default location
147
+ local_env.append_plugin_list do
148
+ Dir[File.join(root, 'vendor', 'plugins', '*')].collect{ |p| File.basename p if File.directory? p }.compact
149
+ end
150
+ end
151
+ end
152
+
153
+ def install_shim
154
+ super
155
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
156
+ ::ActionController::Base.class_eval {
157
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
158
+ }
159
+ end
160
+
161
+ end
162
+ end
163
+ end
164
+ end