wd_newrelic_rpm 3.3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +591 -0
- data/LICENSE +64 -0
- data/README.rdoc +179 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent.rb +467 -0
- data/lib/new_relic/agent/agent.rb +1325 -0
- data/lib/new_relic/agent/beacon_configuration.rb +121 -0
- data/lib/new_relic/agent/browser_monitoring.rb +142 -0
- data/lib/new_relic/agent/busy_calculator.rb +99 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +251 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +29 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
- data/lib/new_relic/agent/method_tracer.rb +528 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/sql_sampler.rb +286 -0
- data/lib/new_relic/agent/stats_engine.rb +26 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
- data/lib/new_relic/agent/transaction_sampler.rb +468 -0
- data/lib/new_relic/agent/worker_loop.rb +89 -0
- data/lib/new_relic/collection_helper.rb +77 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +46 -0
- data/lib/new_relic/control/class_methods.rb +53 -0
- data/lib/new_relic/control/configuration.rb +206 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +31 -0
- data/lib/new_relic/control/frameworks/rails.rb +164 -0
- data/lib/new_relic/control/frameworks/rails3.rb +75 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +179 -0
- data/lib/new_relic/control/instrumentation.rb +100 -0
- data/lib/new_relic/control/logging_methods.rb +143 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +114 -0
- data/lib/new_relic/data_serialization.rb +151 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/language_support.rb +73 -0
- data/lib/new_relic/local_environment.rb +428 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +51 -0
- data/lib/new_relic/metric_spec.rb +76 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +29 -0
- data/lib/new_relic/rack/browser_monitoring.rb +76 -0
- data/lib/new_relic/rack/developer_mode.rb +268 -0
- data/lib/new_relic/recipes.rb +77 -0
- data/lib/new_relic/stats.rb +335 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_sample.rb +261 -0
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +203 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +19 -0
- data/newrelic.yml +265 -0
- data/newrelic_rpm.gemspec +312 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +403 -0
- data/test/new_relic/agent/agent/start_test.rb +255 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +140 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/database_test.rb +149 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +192 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +220 -0
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/agent_test.rb +187 -0
- data/test/new_relic/collection_helper_test.rb +149 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/configuration_test.rb +84 -0
- data/test/new_relic/control/logging_methods_test.rb +185 -0
- data/test/new_relic/control_test.rb +256 -0
- data/test/new_relic/data_serialization_test.rb +208 -0
- data/test/new_relic/delayed_job_injection_test.rb +16 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +74 -0
- data/test/new_relic/stats_test.rb +411 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +389 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +177 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +94 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +155 -0
- data/ui/helpers/developer_mode_helper.rb +357 -0
- data/ui/helpers/google_pie_chart.rb +48 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +53 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- metadata +376 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'new_relic/agent/instrumentation'
|
2
|
+
module NewRelic
|
3
|
+
module Agent
|
4
|
+
module Instrumentation
|
5
|
+
class MetricFrame
|
6
|
+
module Pop
|
7
|
+
|
8
|
+
def clear_thread_metric_frame!
|
9
|
+
Thread.current[:newrelic_metric_frame] = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_new_scope!(metric)
|
13
|
+
agent.stats_engine.scope_name = metric
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_underflow
|
17
|
+
NewRelic::Agent.logger.error "Underflow in metric frames: #{caller.join("\n ")}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def notice_scope_empty
|
21
|
+
transaction_sampler.notice_scope_empty
|
22
|
+
sql_sampler.notice_scope_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
def record_transaction_cpu
|
26
|
+
burn = cpu_burn
|
27
|
+
transaction_sampler.notice_transaction_cpu_time(burn) if burn
|
28
|
+
end
|
29
|
+
|
30
|
+
def normal_cpu_burn
|
31
|
+
return unless @process_cpu_start
|
32
|
+
process_cpu - @process_cpu_start
|
33
|
+
end
|
34
|
+
|
35
|
+
def jruby_cpu_burn
|
36
|
+
return unless @jruby_cpu_start
|
37
|
+
burn = (jruby_cpu_time - @jruby_cpu_start)
|
38
|
+
record_jruby_cpu_burn(burn)
|
39
|
+
burn
|
40
|
+
end
|
41
|
+
|
42
|
+
# we need to do this here because the normal cpu sampler
|
43
|
+
# process doesn't work on JRuby. See the cpu_sampler.rb file
|
44
|
+
# to understand where cpu is recorded for non-jruby processes
|
45
|
+
def record_jruby_cpu_burn(burn)
|
46
|
+
NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).record_data_point(burn)
|
47
|
+
end
|
48
|
+
|
49
|
+
def cpu_burn
|
50
|
+
normal_cpu_burn || jruby_cpu_burn
|
51
|
+
end
|
52
|
+
|
53
|
+
def end_transaction!
|
54
|
+
agent.stats_engine.end_transaction
|
55
|
+
end
|
56
|
+
|
57
|
+
def notify_transaction_sampler(web_transaction)
|
58
|
+
record_transaction_cpu
|
59
|
+
notice_scope_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
def traced?
|
63
|
+
NewRelic::Agent.is_execution_traced?
|
64
|
+
end
|
65
|
+
|
66
|
+
def handle_empty_path_stack(metric)
|
67
|
+
raise 'path stack not empty' unless @path_stack.empty?
|
68
|
+
notify_transaction_sampler(metric.is_web_transaction?) if traced?
|
69
|
+
end_transaction!
|
70
|
+
clear_thread_metric_frame!
|
71
|
+
end
|
72
|
+
|
73
|
+
def current_stack_metric
|
74
|
+
metric_name
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
@name = :net
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(Net) && defined?(Net::HTTP)
|
6
|
+
end
|
7
|
+
|
8
|
+
executes do
|
9
|
+
NewRelic::Agent.logger.debug 'Installing Net instrumentation'
|
10
|
+
end
|
11
|
+
|
12
|
+
executes do
|
13
|
+
Net::HTTP.class_eval do
|
14
|
+
def request_with_newrelic_trace(*args, &block)
|
15
|
+
metrics = ["External/#{@address}/Net::HTTP/#{args[0].method}", "External/#{@address}/all", "External/all"]
|
16
|
+
if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
|
17
|
+
metrics << "External/allWeb"
|
18
|
+
else
|
19
|
+
metrics << "External/allOther"
|
20
|
+
end
|
21
|
+
self.class.trace_execution_scoped metrics do
|
22
|
+
request_without_newrelic_trace(*args, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
alias request_without_newrelic_trace request
|
26
|
+
alias request request_with_newrelic_trace
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
@name = :passenger
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(PhusionPassenger)
|
6
|
+
end
|
7
|
+
|
8
|
+
executes do
|
9
|
+
NewRelic::Agent.logger.debug "Installing Passenger event hooks."
|
10
|
+
|
11
|
+
PhusionPassenger.on_event(:stopping_worker_process) do
|
12
|
+
NewRelic::Agent.logger.debug "Passenger stopping this process, shutdown the agent."
|
13
|
+
NewRelic::Agent.instance.shutdown
|
14
|
+
end
|
15
|
+
|
16
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
17
|
+
# We want to reset the stats from the stats engine in case any carried
|
18
|
+
# over into the spawned process. Don't clear them in case any were
|
19
|
+
# cached. We do this even in conservative spawning.
|
20
|
+
NewRelic::Agent.after_fork(:force_reconnect => true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
DependencyDetection.defer do
|
26
|
+
depends_on do
|
27
|
+
defined?(::Passenger) && defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER)
|
28
|
+
end
|
29
|
+
|
30
|
+
executes do
|
31
|
+
## We're on an older version of passenger
|
32
|
+
## FIXME: This warning is printing on current version of passenger
|
33
|
+
# NewRelic::Agent.logger.warn "An older version of Phusion Passenger has been detected. We recommend using at least release 2.1.1."
|
34
|
+
|
35
|
+
NewRelic::Agent::Instrumentation::MetricFrame.check_server_connection = true
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
module Instrumentation
|
4
|
+
module QueueTime
|
5
|
+
unless defined?(MAIN_HEADER)
|
6
|
+
MAIN_HEADER = 'HTTP_X_REQUEST_START'
|
7
|
+
MIDDLEWARE_HEADER = 'HTTP_X_MIDDLEWARE_START'
|
8
|
+
QUEUE_HEADER = 'HTTP_X_QUEUE_START'
|
9
|
+
ALT_QUEUE_HEADER = 'HTTP_X_QUEUE_TIME'
|
10
|
+
HEROKU_QUEUE_HEADER = 'HTTP_X_HEROKU_QUEUE_WAIT_TIME'
|
11
|
+
APP_HEADER = 'HTTP_X_APPLICATION_START'
|
12
|
+
|
13
|
+
HEADER_REGEX = /([^\s\/,(t=)]+)? ?t=([0-9]+)/
|
14
|
+
SERVER_METRIC = 'WebFrontend/WebServer/'
|
15
|
+
MIDDLEWARE_METRIC = 'Middleware/'
|
16
|
+
# no individual queue metric - more than one queue?!
|
17
|
+
ALL_SERVER_METRIC = 'WebFrontend/WebServer/all'
|
18
|
+
ALL_MIDDLEWARE_METRIC = 'Middleware/all'
|
19
|
+
ALL_QUEUE_METRIC = 'WebFrontend/QueueTime'
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_frontend_headers(headers)
|
23
|
+
# these methods add internal state, so we dup so other parts
|
24
|
+
# of the app don't have to worry about it.
|
25
|
+
# May have performance implications with very large env hashes
|
26
|
+
env = headers.dup
|
27
|
+
add_end_time_header(Time.now, env)
|
28
|
+
middleware_start = parse_middleware_time_from(env)
|
29
|
+
queue_start = parse_queue_time_from(env)
|
30
|
+
server_start = parse_server_time_from(env)
|
31
|
+
# returned for the controller instrumentation
|
32
|
+
[middleware_start, queue_start, server_start].min
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# main method to extract server time info from env hash,
|
38
|
+
# records individual server metrics and one roll-up for all servers
|
39
|
+
def parse_server_time_from(env)
|
40
|
+
end_time = parse_end_time(env)
|
41
|
+
matches = get_matches_from_header(MAIN_HEADER, env)
|
42
|
+
|
43
|
+
record_individual_server_stats(end_time, matches)
|
44
|
+
record_rollup_server_stat(end_time, matches)
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_middleware_time_from(env)
|
48
|
+
end_time = parse_end_time(env)
|
49
|
+
matches = get_matches_from_header(MIDDLEWARE_HEADER, env)
|
50
|
+
|
51
|
+
record_individual_middleware_stats(end_time, matches)
|
52
|
+
oldest_time = record_rollup_middleware_stat(end_time, matches)
|
53
|
+
# notice this bit: we reset the end time to the earliest
|
54
|
+
# middleware tag so that other frontend metrics don't
|
55
|
+
# include this time.
|
56
|
+
add_end_time_header(oldest_time, env)
|
57
|
+
oldest_time
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_queue_time_from(env)
|
61
|
+
oldest_time = nil
|
62
|
+
end_time = parse_end_time(env)
|
63
|
+
alternate_length = check_for_alternate_queue_length(env)
|
64
|
+
if alternate_length
|
65
|
+
# skip all that fancy-dan stuff
|
66
|
+
NewRelic::Agent.get_stats(ALL_QUEUE_METRIC).trace_call(alternate_length)
|
67
|
+
oldest_time = (end_time - alternate_length) # should be a time
|
68
|
+
else
|
69
|
+
matches = get_matches_from_header(QUEUE_HEADER, env)
|
70
|
+
oldest_time = record_rollup_queue_stat(end_time, matches)
|
71
|
+
end
|
72
|
+
# notice this bit: we reset the end time to the earliest
|
73
|
+
# queue tag or the start time minus the queue time so that
|
74
|
+
# other frontend metrics don't include this time.
|
75
|
+
add_end_time_header(oldest_time, env)
|
76
|
+
oldest_time
|
77
|
+
end
|
78
|
+
|
79
|
+
def check_for_alternate_queue_length(env)
|
80
|
+
heroku_length = check_for_heroku_queue_length(env)
|
81
|
+
return heroku_length if heroku_length
|
82
|
+
header = env[ALT_QUEUE_HEADER]
|
83
|
+
return nil unless header
|
84
|
+
(header.gsub('t=', '').to_i / 1_000_000.0)
|
85
|
+
end
|
86
|
+
|
87
|
+
def check_for_heroku_queue_length(env)
|
88
|
+
header = env[HEROKU_QUEUE_HEADER]
|
89
|
+
return nil unless header
|
90
|
+
(header.gsub(/[^0-9]/, '').to_i / 1_000.0)
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_matches_from_header(header, env)
|
94
|
+
return [] if env.nil?
|
95
|
+
get_matches(env[header]).map do |name, time|
|
96
|
+
convert_to_name_time_pair(name, time)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_matches(string)
|
101
|
+
string.to_s.scan(HEADER_REGEX)
|
102
|
+
end
|
103
|
+
|
104
|
+
def convert_to_name_time_pair(name, time)
|
105
|
+
[name, convert_from_microseconds(time.to_i)]
|
106
|
+
end
|
107
|
+
|
108
|
+
def record_individual_stat_of_type(type, end_time, matches)
|
109
|
+
matches = matches.sort_by {|name, time| time }
|
110
|
+
matches.reverse!
|
111
|
+
matches.inject(end_time) {|end_time, pair|
|
112
|
+
name, time = pair
|
113
|
+
self.send(type, name, time, end_time) if name
|
114
|
+
time
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
# goes through the list of servers and records each one in
|
119
|
+
# reverse order, subtracting the time for each successive
|
120
|
+
# server from the earlier ones in the list.
|
121
|
+
# an example because it's complicated:
|
122
|
+
# start data:
|
123
|
+
# [['a', Time.at(1000)], ['b', Time.at(1001)]], start time: Time.at(1002)
|
124
|
+
# initial run: Time.at(1002), ['b', Time.at(1001)]
|
125
|
+
# next: Time.at(1001), ['a', Time.at(1000)]
|
126
|
+
# see tests for more
|
127
|
+
def record_individual_server_stats(end_time, matches) # (Time, [[String, Time]]) -> nil
|
128
|
+
record_individual_stat_of_type(:record_server_time_for, end_time, matches)
|
129
|
+
end
|
130
|
+
|
131
|
+
def record_individual_middleware_stats(end_time, matches)
|
132
|
+
record_individual_stat_of_type(:record_middleware_time_for, end_time, matches)
|
133
|
+
end
|
134
|
+
|
135
|
+
# records the total time for all servers in a rollup metric
|
136
|
+
def record_rollup_server_stat(end_time, matches) # (Time, [String, Time]) -> nil
|
137
|
+
record_rollup_stat_of_type(ALL_SERVER_METRIC, end_time, matches)
|
138
|
+
end
|
139
|
+
|
140
|
+
def record_rollup_middleware_stat(end_time, matches)
|
141
|
+
record_rollup_stat_of_type(ALL_MIDDLEWARE_METRIC, end_time, matches)
|
142
|
+
end
|
143
|
+
|
144
|
+
def record_rollup_queue_stat(end_time, matches)
|
145
|
+
record_rollup_stat_of_type(ALL_QUEUE_METRIC, end_time, matches)
|
146
|
+
end
|
147
|
+
|
148
|
+
def record_rollup_stat_of_type(metric, end_time, matches)
|
149
|
+
oldest_time = find_oldest_time(matches) || end_time
|
150
|
+
record_time_stat(metric, oldest_time, end_time)
|
151
|
+
oldest_time
|
152
|
+
end
|
153
|
+
|
154
|
+
# searches for the first server to touch a request
|
155
|
+
def find_oldest_time(matches) # [[String, Time]] -> Time
|
156
|
+
matches.map do |name, time|
|
157
|
+
time
|
158
|
+
end.min
|
159
|
+
end
|
160
|
+
|
161
|
+
# basically just assembles the metric name
|
162
|
+
def record_server_time_for(name, start_time, end_time) # (Maybe String, Time, Time) -> nil
|
163
|
+
record_time_stat(SERVER_METRIC + name, start_time, end_time) if name
|
164
|
+
end
|
165
|
+
|
166
|
+
def record_middleware_time_for(name, start_time, end_time)
|
167
|
+
record_time_stat(MIDDLEWARE_METRIC + name, start_time, end_time)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Checks that the time is not negative, and does the actual
|
171
|
+
# data recording
|
172
|
+
def record_time_stat(name, start_time, end_time) # (String, Time, Time) -> nil
|
173
|
+
total_time = end_time - start_time
|
174
|
+
if total_time < 0
|
175
|
+
raise "should not provide an end time less than start time: #{end_time.strftime('%s.%N')} is less than #{start_time.strftime('%s.%N')}. total time is #{total_time}."
|
176
|
+
else
|
177
|
+
NewRelic::Agent.get_stats(name).trace_call(total_time)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def add_end_time_header(end_time, env) # (Time, Env) -> nil
|
182
|
+
return unless end_time
|
183
|
+
env[APP_HEADER] = "t=#{convert_to_microseconds(end_time)}"
|
184
|
+
end
|
185
|
+
|
186
|
+
def parse_end_time(env)
|
187
|
+
header = env[APP_HEADER]
|
188
|
+
return Time.now unless header
|
189
|
+
convert_from_microseconds(header.gsub('t=', '').to_i)
|
190
|
+
end
|
191
|
+
|
192
|
+
# convert a time to the value provided by the header, for convenience
|
193
|
+
def convert_to_microseconds(time) # Time -> Int
|
194
|
+
raise TypeError.new('Cannot convert a non-time into microseconds') unless time.is_a?(Time) || time.is_a?(Numeric)
|
195
|
+
return time if time.is_a?(Numeric)
|
196
|
+
(time.to_f * 1_000_000).to_i
|
197
|
+
end
|
198
|
+
|
199
|
+
# convert a time from the header value (time in microseconds)
|
200
|
+
# into a ruby time object
|
201
|
+
def convert_from_microseconds(int) # Int -> Time
|
202
|
+
raise TypeError.new('Cannot convert a non-number into a time') unless int.is_a?(Time) || int.is_a?(Numeric)
|
203
|
+
return int if int.is_a?(Time)
|
204
|
+
Time.at((int / 1_000_000.0))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
2
|
+
|
3
|
+
module NewRelic
|
4
|
+
module Agent
|
5
|
+
module Instrumentation
|
6
|
+
# == Instrumentation for Rack
|
7
|
+
#
|
8
|
+
# New Relic will instrument a #call method as if it were a controller
|
9
|
+
# action, collecting transaction traces and errors. The middleware will
|
10
|
+
# be identified only by it's class, so if you want to instrument multiple
|
11
|
+
# actions in a middleware, you need to use
|
12
|
+
# NewRelic::Agent::Instrumentation::ControllerInstrumentation::ClassMethods#add_transaction_tracer
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# require 'newrelic_rpm'
|
16
|
+
# require 'new_relic/agent/instrumentation/rack'
|
17
|
+
# class Middleware
|
18
|
+
# def call(env)
|
19
|
+
# ...
|
20
|
+
# end
|
21
|
+
# # Do the include after the call method is defined:
|
22
|
+
# include NewRelic::Agent::Instrumentation::Rack
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# == Instrumenting Metal and Cascading Middlewares
|
26
|
+
#
|
27
|
+
# Metal apps and apps belonging to Rack::Cascade middleware
|
28
|
+
# follow a convention of returning a 404 for all requests except
|
29
|
+
# the ones they are set up to handle. This means that New Relic
|
30
|
+
# needs to ignore these calls when they return a 404.
|
31
|
+
#
|
32
|
+
# In these cases, you should not include or extend the Rack
|
33
|
+
# module but instead include
|
34
|
+
# NewRelic::Agent::Instrumentation::ControllerInstrumentation.
|
35
|
+
# Here's how that might look for a Metal app:
|
36
|
+
#
|
37
|
+
# require 'new_relic/agent/instrumentation/controller_instrumentation'
|
38
|
+
# class MetalApp
|
39
|
+
# extend NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
40
|
+
# def self.call(env)
|
41
|
+
# if should_do_my_thing?
|
42
|
+
# perform_action_with_newrelic_trace(:category => :rack) do
|
43
|
+
# return my_response(env)
|
44
|
+
# end
|
45
|
+
# else
|
46
|
+
# return [404, {"Content-Type" => "text/html"}, ["Not Found"]]
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# == Overriding the metric name
|
52
|
+
#
|
53
|
+
# By default the middleware is identified only by its class, but if you want to
|
54
|
+
# be more specific and pass in name, then omit including the Rack instrumentation
|
55
|
+
# and instead follow this example:
|
56
|
+
#
|
57
|
+
# require 'newrelic_rpm'
|
58
|
+
# require 'new_relic/agent/instrumentation/controller_instrumentation'
|
59
|
+
# class Middleware
|
60
|
+
# include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
61
|
+
# def call(env)
|
62
|
+
# ...
|
63
|
+
# end
|
64
|
+
# add_transaction_tracer :call, :category => :rack, :name => 'my app'
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
module Rack
|
68
|
+
def newrelic_request_headers
|
69
|
+
@newrelic_request.env
|
70
|
+
end
|
71
|
+
def call_with_newrelic(*args)
|
72
|
+
@newrelic_request = ::Rack::Request.new(args.first)
|
73
|
+
perform_action_with_newrelic_trace(:category => :rack, :request => @newrelic_request) do
|
74
|
+
result = call_without_newrelic(*args)
|
75
|
+
# Ignore cascaded calls
|
76
|
+
MetricFrame.abort_transaction! if result.first == 404
|
77
|
+
result
|
78
|
+
end
|
79
|
+
end
|
80
|
+
def self.included middleware #:nodoc:
|
81
|
+
middleware.class_eval do
|
82
|
+
alias call_without_newrelic call
|
83
|
+
alias call call_with_newrelic
|
84
|
+
end
|
85
|
+
end
|
86
|
+
include ControllerInstrumentation
|
87
|
+
def self.extended middleware #:nodoc:
|
88
|
+
middleware.class_eval do
|
89
|
+
class << self
|
90
|
+
alias call_without_newrelic call
|
91
|
+
alias call call_with_newrelic
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|