wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -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/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 +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -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 +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -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/method_tracer.rb +528 -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 +143 -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/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -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.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -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 +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -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 +203 -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 +312 -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/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,50 @@
1
+ # A Sampler is used to capture meaningful metrics in a background thread
2
+ # periodically. They will either be invoked once a minute just before the
3
+ # data is sent to the agent (default) or every 10 seconds, when #use_harvest_sampler?
4
+ # returns false.
5
+ #
6
+ # Samplers can be added to New Relic by subclassing NewRelic::Agent::Sampler.
7
+ # Instances are created when the agent is enabled and installed. Subclasses
8
+ # are registered for instantiation automatically.
9
+ module NewRelic
10
+ module Agent
11
+ class Sampler
12
+
13
+ # Exception denotes a sampler is not available and it will not be registered.
14
+ class Unsupported < StandardError; end
15
+
16
+ attr_accessor :stats_engine
17
+ attr_reader :id
18
+ @sampler_classes = []
19
+
20
+ def self.inherited(subclass)
21
+ @sampler_classes << subclass
22
+ end
23
+
24
+ # Override with check. Called before instantiating.
25
+ def self.supported_on_this_platform?
26
+ true
27
+ end
28
+
29
+ # Override to use the periodic sampler instead of running the sampler on the
30
+ # minute during harvests.
31
+ def self.use_harvest_sampler?
32
+ true
33
+ end
34
+
35
+ def self.sampler_classes
36
+ @sampler_classes
37
+ end
38
+
39
+ def initialize(id)
40
+ @id = id
41
+ end
42
+
43
+ def poll
44
+ raise "Implement in the subclass"
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,58 @@
1
+ require 'new_relic/agent/sampler'
2
+
3
+ module NewRelic
4
+ module Agent
5
+ module Samplers
6
+ class CpuSampler < NewRelic::Agent::Sampler
7
+ attr_reader :last_time
8
+ def initialize
9
+ super :cpu
10
+ poll
11
+ end
12
+
13
+ def user_util_stats
14
+ stats_engine.get_stats_no_scope("CPU/User/Utilization")
15
+ end
16
+ def system_util_stats
17
+ stats_engine.get_stats_no_scope("CPU/System/Utilization")
18
+ end
19
+ def usertime_stats
20
+ stats_engine.get_stats_no_scope("CPU/User Time")
21
+ end
22
+ def systemtime_stats
23
+ stats_engine.get_stats_no_scope("CPU/System Time")
24
+ end
25
+
26
+ def self.supported_on_this_platform?
27
+ # Process.times on JRuby reports wall clock elapsed time,
28
+ # not actual cpu time used, so we cannot use this sampler there.
29
+ not defined?(JRuby)
30
+ end
31
+
32
+ def poll
33
+ now = Time.now
34
+ t = Process.times
35
+ if @last_time
36
+ elapsed = now - @last_time
37
+ return if elapsed < 1 # Causing some kind of math underflow
38
+ num_processors = NewRelic::Control.instance.local_env.processors || 1
39
+ usertime = t.utime - @last_utime
40
+ systemtime = t.stime - @last_stime
41
+
42
+ systemtime_stats.record_data_point(systemtime) if systemtime >= 0
43
+ usertime_stats.record_data_point(usertime) if usertime >= 0
44
+
45
+ # Calculate the true utilization by taking cpu times and dividing by
46
+ # elapsed time X num_processors.
47
+ user_util_stats.record_data_point usertime / (elapsed * num_processors)
48
+ system_util_stats.record_data_point systemtime / (elapsed * num_processors)
49
+ end
50
+ @last_utime = t.utime
51
+ @last_stime = t.stime
52
+ @last_time = now
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,40 @@
1
+ require 'new_relic/agent/sampler'
2
+ require 'new_relic/delayed_job_injection'
3
+
4
+ module NewRelic
5
+ module Agent
6
+ module Samplers
7
+ class DelayedJobLockSampler < NewRelic::Agent::Sampler
8
+ def initialize
9
+ super :delayed_job_lock
10
+ raise Unsupported, "DJ instrumentation disabled" if NewRelic::Control.instance['disable_dj']
11
+ raise Unsupported, "No DJ worker present" unless NewRelic::DelayedJobInjection.worker_name
12
+ end
13
+
14
+ def stats
15
+ stats_engine.get_stats("Custom/DJ Locked Jobs", false)
16
+ end
17
+
18
+ def local_env
19
+ NewRelic::Control.instance.local_env
20
+ end
21
+
22
+ def worker_name
23
+ local_env.dispatcher_instance_id
24
+ end
25
+
26
+ def locked_jobs
27
+ Delayed::Job.count(:conditions => {:locked_by => NewRelic::DelayedJobInjection.worker_name})
28
+ end
29
+
30
+ def self.supported_on_this_platform?
31
+ defined?(Delayed::Job)
32
+ end
33
+
34
+ def poll
35
+ stats.record_data_point locked_jobs
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,143 @@
1
+ require 'new_relic/agent/sampler'
2
+
3
+ module NewRelic
4
+ module Agent
5
+ module Samplers
6
+
7
+ class MemorySampler < NewRelic::Agent::Sampler
8
+ attr_accessor :sampler
9
+
10
+ def initialize
11
+ super :memory
12
+ # macos, linux, solaris
13
+ if defined? JRuby
14
+ @sampler = JavaHeapSampler.new
15
+ elsif platform =~ /linux/
16
+ @sampler = ProcStatus.new
17
+ if !@sampler.can_run?
18
+ NewRelic::Agent.instance.warn.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
19
+ @sampler = ShellPS.new("ps -o rsz")
20
+ else
21
+ NewRelic::Agent.instance.log.debug "Using /proc/#{$$}/status for reading process memory."
22
+ end
23
+ elsif platform =~ /darwin9/ # 10.5
24
+ @sampler = ShellPS.new("ps -o rsz")
25
+ elsif platform =~ /darwin1[01]/ # 10.6 & 10.7
26
+ @sampler = ShellPS.new("ps -o rss")
27
+ elsif platform =~ /freebsd/
28
+ @sampler = ShellPS.new("ps -o rss")
29
+ elsif platform =~ /solaris/
30
+ @sampler = ShellPS.new("/usr/bin/ps -o rss -p")
31
+ end
32
+
33
+ raise Unsupported, "Unsupported platform for getting memory: #{platform}" if @sampler.nil?
34
+ raise Unsupported, "Unable to run #{@sampler}" unless @sampler.can_run?
35
+ end
36
+
37
+ def self.supported_on_this_platform?
38
+ defined?(JRuby) or platform =~ /linux|darwin9|darwin10|freebsd|solaris/
39
+ end
40
+
41
+ def self.platform
42
+ if RUBY_PLATFORM =~ /java/
43
+ %x[uname -s].downcase
44
+ else
45
+ RUBY_PLATFORM.downcase
46
+ end
47
+ end
48
+ def platform
49
+ NewRelic::Agent::Samplers::MemorySampler.platform
50
+ end
51
+
52
+ def stats
53
+ stats_engine.get_stats("Memory/Physical", false)
54
+ end
55
+ def poll
56
+ sample = @sampler.get_sample
57
+ stats.record_data_point sample if sample
58
+ stats
59
+ end
60
+ class Base
61
+ def can_run?
62
+ return false if @broken
63
+ m = get_memory rescue nil
64
+ m && m > 0
65
+ end
66
+ def get_sample
67
+ return nil if @broken
68
+ begin
69
+ m = get_memory
70
+ if m.nil?
71
+ NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
72
+ @broken = true
73
+ end
74
+ return m
75
+ rescue => e
76
+ NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. (#{e})"
77
+ NewRelic::Agent.instance.log.debug e.backtrace.join("\n ")
78
+ NewRelic::Agent.instance.log.error "Disabling memory sampler."
79
+ @broken = true
80
+ return nil
81
+ end
82
+ end
83
+ end
84
+
85
+ class JavaHeapSampler < Base
86
+
87
+ def get_memory
88
+ raise "Can't sample Java heap unless running in JRuby" unless defined? JRuby
89
+ java.lang.Runtime.getRuntime.totalMemory / (1024 * 1024).to_f rescue nil
90
+ end
91
+ def to_s
92
+ "JRuby Java heap sampler"
93
+ end
94
+ end
95
+
96
+ class ShellPS < Base
97
+ def initialize(command)
98
+ super()
99
+ @command = command
100
+ end
101
+ # Returns the amount of resident memory this process is using in MB
102
+ #
103
+ def get_memory
104
+ process = $$
105
+ memory = `#{@command} #{process}`.split("\n")[1].to_f / 1024.0 rescue nil
106
+ # if for some reason the ps command doesn't work on the resident os,
107
+ # then don't execute it any more.
108
+ raise "Faulty command: `#{@command} #{process}`" if memory.nil? || memory <= 0
109
+ memory
110
+ end
111
+ def to_s
112
+ "shell command sampler: #{@command}"
113
+ end
114
+ end
115
+
116
+ # ProcStatus
117
+ #
118
+ # A class that samples memory by reading the file /proc/$$/status, which is specific to linux
119
+ #
120
+ class ProcStatus < Base
121
+
122
+ # Returns the amount of resident memory this process is using in MB
123
+ #
124
+ def get_memory
125
+ proc_status = File.open(proc_status_file, "r") {|f| f.read_nonblock(4096).strip }
126
+ if proc_status =~ /RSS:\s*(\d+) kB/i
127
+ return $1.to_f / 1024.0
128
+ end
129
+ raise "Unable to find RSS in #{proc_status_file}"
130
+ end
131
+
132
+ def proc_status_file
133
+ "/proc/#{$$}/status"
134
+ end
135
+
136
+ def to_s
137
+ "proc status file sampler: #{proc_status_file}"
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,26 @@
1
+ require 'new_relic/agent/sampler'
2
+
3
+ module NewRelic
4
+ module Agent
5
+ module Samplers
6
+ class ObjectSampler < NewRelic::Agent::Sampler
7
+
8
+ def initialize
9
+ super :objects
10
+ end
11
+
12
+ def stats
13
+ stats_engine.get_stats_no_scope("GC/objects")
14
+ end
15
+
16
+ def self.supported_on_this_platform?
17
+ defined?(ObjectSpace) && ObjectSpace.respond_to?(:live_objects)
18
+ end
19
+
20
+ def poll
21
+ stats.record_data_point(ObjectSpace.live_objects)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # This agent is loaded by the plug when the plug-in is disabled
2
+ # It recreates just enough of the API to not break any clients that
3
+ # invoke the Agent.
4
+ module NewRelic
5
+ module Agent
6
+ class ShimAgent < NewRelic::Agent::Agent
7
+ def self.instance
8
+ @instance ||= self.new
9
+ end
10
+ def initialize
11
+ super
12
+ @stats_engine.extend NewRelic::Agent::StatsEngine::Shim
13
+ @stats_engine.extend NewRelic::Agent::StatsEngine::Transactions::Shim
14
+ @transaction_sampler.extend NewRelic::Agent::TransactionSampler::Shim
15
+ @sql_sampler.extend NewRelic::Agent::SqlSampler::Shim
16
+ @error_collector.extend NewRelic::Agent::ErrorCollector::Shim
17
+ end
18
+ def after_fork *args; end
19
+ def start *args; end
20
+ def shutdown *args; end
21
+ def serialize; end
22
+ def merge_data_from *args; end
23
+ def push_trace_execution_flag *args; end
24
+ def pop_trace_execution_flag *args; end
25
+ def browser_timing_header; "" end
26
+ def browser_timing_footer; "" end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,286 @@
1
+ require 'new_relic/agent'
2
+ require 'new_relic/control'
3
+ module NewRelic
4
+ module Agent
5
+
6
+ class SqlSampler
7
+
8
+ # Module defining methods stubbed out when the agent is disabled
9
+ module Shim #:nodoc:
10
+ def notice_scope_empty(*args); end
11
+ def notice_first_scope_push(*args); end
12
+ def notice_transaction(*args); end
13
+ end
14
+
15
+ attr_reader :disabled
16
+
17
+ # this is for unit tests only
18
+ attr_reader :sql_traces
19
+
20
+ def initialize
21
+ configure!
22
+ @sql_traces = {}
23
+ clear_transaction_data
24
+
25
+ # This lock is used to synchronize access to the @last_sample
26
+ # and related variables. It can become necessary on JRuby or
27
+ # any 'honest-to-god'-multithreaded system
28
+ @samples_lock = Mutex.new
29
+ end
30
+
31
+ def configure!
32
+ @explain_threshold = config.fetch('explain_threshold', 0.5).to_f
33
+ @explain_enabled = config.fetch('explain_enabled', true)
34
+ @stack_trace_threshold = config.fetch('stack_trace_threshold',
35
+ 0.5).to_f
36
+ if config.fetch('enabled', true) &&
37
+ NewRelic::Control.instance['transaction_tracer'] &&
38
+ NewRelic::Control.instance['transaction_tracer'].fetch('enabled',
39
+ true) &&
40
+ NewRelic::Control.instance.fetch('collect_traces', true)
41
+ enable
42
+ else
43
+ disable
44
+ end
45
+ end
46
+
47
+ def config
48
+ self.class.config
49
+ end
50
+
51
+ def self.config
52
+ control = NewRelic::Control.instance
53
+ txn_config = control.fetch('transaction_tracer', {})
54
+
55
+ if txn_config.fetch('enabled', true) && control.has_slow_sql_config?
56
+ txn_config['enabled'] = control['slow_sql']['enabled']
57
+ end
58
+
59
+ txn_config
60
+ end
61
+
62
+ # Enable the sql sampler - this also registers it with
63
+ # the statistics engine.
64
+ def enable
65
+ @disabled = false
66
+ end
67
+
68
+ # Disable the sql sampler - this also deregisters it
69
+ # with the statistics engine.
70
+ def disable
71
+ @disabled = true
72
+ end
73
+
74
+ def enabled?
75
+ !@disabled
76
+ end
77
+
78
+ def notice_transaction(path, uri=nil, params={})
79
+ if NewRelic::Agent.instance.transaction_sampler.builder
80
+ guid = NewRelic::Agent.instance.transaction_sampler.builder.sample.guid
81
+ end
82
+ transaction_data.set_transaction_info(path, uri, params, guid) if !disabled && transaction_data
83
+ end
84
+
85
+ def notice_first_scope_push(time)
86
+ create_transaction_data
87
+ end
88
+
89
+ def create_transaction_data
90
+ Thread.current[:new_relic_sql_data] = TransactionSqlData.new
91
+ end
92
+
93
+ def transaction_data
94
+ Thread.current[:new_relic_sql_data]
95
+ end
96
+
97
+ def clear_transaction_data
98
+ Thread.current[:new_relic_sql_data] = nil
99
+ end
100
+
101
+ # This is called when we are done with the transaction.
102
+ def notice_scope_empty(time=Time.now)
103
+ data = transaction_data
104
+ clear_transaction_data
105
+
106
+ if data.sql_data.size > 0
107
+ @samples_lock.synchronize do
108
+ NewRelic::Agent.instance.log.debug "Harvesting #{data.sql_data.size} slow transaction sql statement(s)"
109
+ #FIXME get tx name and uri
110
+ harvest_slow_sql data
111
+ end
112
+ end
113
+ end
114
+
115
+ # this should always be called under the @samples_lock
116
+ def harvest_slow_sql(transaction_sql_data)
117
+ transaction_sql_data.sql_data.each do |sql_item|
118
+ normalized_sql = sql_item.normalize
119
+ sql_trace = @sql_traces[normalized_sql]
120
+ if sql_trace
121
+ sql_trace.aggregate(sql_item, transaction_sql_data.path,
122
+ transaction_sql_data.uri)
123
+ else
124
+ @sql_traces[normalized_sql] = SqlTrace.new(normalized_sql,
125
+ sql_item, transaction_sql_data.path, transaction_sql_data.uri)
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+ def notice_sql(sql, metric_name, config, duration)
132
+ return unless transaction_data
133
+ if NewRelic::Agent.is_sql_recorded?
134
+ if duration > @explain_threshold
135
+ backtrace = caller.join("\n")
136
+ transaction_data.sql_data << SlowSql.new(sql, metric_name, config,
137
+ duration, backtrace)
138
+ end
139
+ end
140
+ end
141
+
142
+ def merge(sql_traces)
143
+ @samples_lock.synchronize do
144
+ #FIXME we need to merge the sql_traces array back into the @sql_traces hash
145
+ # @sql_traces.merge! sql_traces
146
+ end
147
+ end
148
+
149
+ def harvest
150
+ return [] if disabled
151
+ result = []
152
+ @samples_lock.synchronize do
153
+ result = @sql_traces.values
154
+ @sql_traces = {}
155
+ end
156
+ slowest = result.sort{|a,b| b.max_call_time <=> a.max_call_time}[0,10]
157
+ slowest.each {|trace| trace.prepare_to_send }
158
+ slowest
159
+ end
160
+
161
+ # reset samples without rebooting the web server
162
+ def reset!
163
+ end
164
+ end
165
+
166
+ class TransactionSqlData
167
+ attr_reader :path
168
+ attr_reader :uri
169
+ attr_reader :params
170
+ attr_reader :sql_data
171
+ attr_reader :guid
172
+
173
+ def initialize
174
+ @sql_data = []
175
+ end
176
+
177
+ def set_transaction_info(path, uri, params, guid)
178
+ @path = path
179
+ @uri = uri
180
+ @params = params
181
+ @guid = guid
182
+ end
183
+ end
184
+
185
+ class SlowSql
186
+ attr_reader :sql
187
+ attr_reader :metric_name
188
+ attr_reader :duration
189
+ attr_reader :backtrace
190
+
191
+ def initialize(sql, metric_name, config, duration, backtrace = nil)
192
+ @sql = sql
193
+ @metric_name = metric_name
194
+ @config = config
195
+ @duration = duration
196
+ @backtrace = backtrace
197
+ end
198
+
199
+ def obfuscate
200
+ NewRelic::Agent::Database.obfuscate_sql(@sql)
201
+ end
202
+
203
+ def normalize
204
+ NewRelic::Agent::Database::Obfuscator.instance \
205
+ .default_sql_obfuscator(@sql).gsub(/\?\s*\,\s*/, '').gsub(/\s/, '')
206
+ end
207
+
208
+ def explain
209
+ NewRelic::Agent::Database.explain_sql(@sql, @config)
210
+ end
211
+ end
212
+
213
+ class SqlTrace < MethodTraceStats
214
+ attr_reader :path
215
+ attr_reader :url
216
+ attr_reader :sql_id
217
+ attr_reader :sql
218
+ attr_reader :database_metric_name
219
+ attr_reader :params
220
+
221
+ def initialize(normalized_query, slow_sql, path, uri)
222
+ super()
223
+ @params = {} #FIXME
224
+ @sql_id = consistent_hash(normalized_query)
225
+ set_primary slow_sql, path, uri
226
+ record_data_point slow_sql.duration
227
+ end
228
+
229
+ def set_primary(slow_sql, path, uri)
230
+ @slow_sql = slow_sql
231
+ @sql = slow_sql.sql
232
+ @database_metric_name = slow_sql.metric_name
233
+ @path = path
234
+ @url = uri
235
+ # FIXME
236
+ @params[:backtrace] = slow_sql.backtrace if slow_sql.backtrace
237
+ end
238
+
239
+ def aggregate(slow_sql, path, uri)
240
+ if slow_sql.duration > max_call_time
241
+ set_primary slow_sql, path, uri
242
+ end
243
+
244
+ record_data_point slow_sql.duration
245
+ end
246
+
247
+ def prepare_to_send
248
+ begin
249
+ params[:explain_plan] = @slow_sql.explain if need_to_explain?
250
+ ensure
251
+ NewRelic::Agent::Database.close_connections
252
+ end
253
+ @sql = @slow_sql.obfuscate if need_to_obfuscate?
254
+ end
255
+
256
+ def agent_config
257
+ NewRelic::Agent::SqlSampler.config
258
+ end
259
+
260
+ def need_to_obfuscate?
261
+ agent_config['record_sql'] == 'obfuscated'
262
+ end
263
+
264
+ def need_to_explain?
265
+ agent_config['explain_enabled']
266
+ end
267
+
268
+ def to_json(*a)
269
+ [@path, @url, @sql_id, @sql, @database_metric_name, @call_count, @total_call_time, @min_call_time, @max_call_time, @params].to_json(*a)
270
+ end
271
+
272
+ private
273
+
274
+ def consistent_hash(string)
275
+ if NewRelic::LanguageSupport.using_version?('1.9.2')
276
+ # String#hash is salted differently on every VM start in 1.9
277
+ require 'digest/md5'
278
+ Digest::MD5.hexdigest(string).hex
279
+ else
280
+ string.hash
281
+ end.modulo(2**31-1)
282
+ # modulo ensures sql_id fits in an INT(11)
283
+ end
284
+ end
285
+ end
286
+ end