wd_newrelic_rpm 3.3.4.1 → 3.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +317 -39
- data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
- data/Gemfile +16 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +71 -55
- data/Rakefile +62 -0
- data/bin/mongrel_rpm +1 -1
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/init.rb +31 -0
- data/lib/new_relic/agent.rb +31 -60
- data/lib/new_relic/agent/agent.rb +277 -502
- data/lib/new_relic/agent/agent_logger.rb +165 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +36 -50
- data/lib/new_relic/agent/browser_monitoring.rb +114 -61
- data/lib/new_relic/agent/busy_calculator.rb +14 -6
- data/lib/new_relic/agent/configuration.rb +74 -0
- data/lib/new_relic/agent/configuration/defaults.rb +126 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
- data/lib/new_relic/agent/configuration/manager.rb +136 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
- data/lib/new_relic/agent/configuration/server_source.rb +27 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
- data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
- data/lib/new_relic/agent/database.rb +39 -26
- data/lib/new_relic/agent/error_collector.rb +48 -49
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
- data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +11 -9
- data/lib/new_relic/agent/new_relic_service.rb +379 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
- data/lib/new_relic/agent/pipe_service.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
- data/lib/new_relic/agent/sql_sampler.rb +31 -74
- data/lib/new_relic/agent/stats_engine.rb +0 -5
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
- data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
- data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
- data/lib/new_relic/agent/thread.rb +32 -0
- data/lib/new_relic/agent/thread_profiler.rb +306 -0
- data/lib/new_relic/agent/transaction_info.rb +24 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
- data/lib/new_relic/agent/transaction_sampler.rb +49 -65
- data/lib/new_relic/agent/worker_loop.rb +31 -25
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +19 -10
- data/lib/new_relic/control.rb +1 -3
- data/lib/new_relic/control/class_methods.rb +10 -5
- data/lib/new_relic/control/frameworks/merb.rb +0 -6
- data/lib/new_relic/control/frameworks/rails.rb +30 -45
- data/lib/new_relic/control/frameworks/rails3.rb +23 -18
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +2 -23
- data/lib/new_relic/control/instance_methods.rb +35 -73
- data/lib/new_relic/control/instrumentation.rb +7 -12
- data/lib/new_relic/control/server_methods.rb +17 -19
- data/lib/new_relic/delayed_job_injection.rb +2 -2
- data/lib/new_relic/helper.rb +34 -0
- data/lib/new_relic/language_support.rb +56 -37
- data/lib/new_relic/local_environment.rb +32 -67
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/metric_spec.rb +7 -3
- data/lib/new_relic/noticed_error.rb +32 -9
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/browser_monitoring.rb +34 -25
- data/lib/new_relic/rack/developer_mode.rb +3 -0
- data/lib/new_relic/rack/error_collector.rb +56 -0
- data/lib/new_relic/stats.rb +9 -7
- data/lib/new_relic/transaction_sample.rb +19 -18
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +19 -3
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/tasks/tests.rake +6 -8
- data/newrelic.yml +15 -32
- data/newrelic_rpm.gemspec +224 -43
- data/newrelic_rpm.gemspec.erb +54 -0
- data/test/config/newrelic.yml +4 -3
- data/test/config/test_control.rb +18 -18
- data/test/fixtures/gemspec_no_build.rb +442 -0
- data/test/fixtures/gemspec_with_build.rb +442 -0
- data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +85 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +162 -0
- data/test/multiverse/script/run_one +3 -0
- data/test/multiverse/script/runner +9 -0
- data/test/multiverse/suites/active_record/Envfile +13 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
- data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
- data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
- data/test/multiverse/suites/agent_only/Envfile +4 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
- data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
- data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/logging/Envfile +4 -0
- data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
- data/test/multiverse/suites/logging/logging_test.rb +143 -0
- data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
- data/test/multiverse/suites/no_load/Envfile +2 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
- data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
- data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
- data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
- data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
- data/test/multiverse/suites/rails_3_views/Envfile +16 -0
- data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
- data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
- data/test/multiverse/suites/resque/Envfile +21 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
- data/test/multiverse/suites/sinatra/Envfile +13 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
- data/test/multiverse/test/multiverse_test.rb +55 -0
- data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
- data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
- data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
- data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
- data/test/new_relic/agent/agent/connect_test.rb +151 -227
- data/test/new_relic/agent/agent/start_test.rb +68 -118
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +116 -30
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
- data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
- data/test/new_relic/agent/busy_calculator_test.rb +7 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
- data/test/new_relic/agent/configuration/manager_test.rb +204 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
- data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
- data/test/new_relic/agent/database_test.rb +12 -11
- data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
- data/test/new_relic/agent/error_collector_test.rb +33 -19
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
- data/test/new_relic/agent/method_tracer_test.rb +7 -6
- data/test/new_relic/agent/mock_scope_listener.rb +3 -0
- data/test/new_relic/agent/new_relic_service_test.rb +376 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +27 -50
- data/test/new_relic/agent/sql_sampler_test.rb +81 -56
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
- data/test/new_relic/agent/stats_engine_test.rb +17 -8
- data/test/new_relic/agent/thread_profiler_test.rb +537 -0
- data/test/new_relic/agent/thread_test.rb +89 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_info_test.rb +45 -4
- data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
- data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
- data/test/new_relic/agent/worker_loop_test.rb +26 -11
- data/test/new_relic/agent_test.rb +113 -33
- data/test/new_relic/collection_helper_test.rb +7 -8
- data/test/new_relic/command/deployments_test.rb +18 -2
- data/test/new_relic/control/class_methods_test.rb +0 -18
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control_test.rb +96 -137
- data/test/new_relic/delayed_job_injection_test.rb +6 -1
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +283 -0
- data/test/new_relic/fake_service.rb +53 -0
- data/test/new_relic/fakes_sending_data.rb +30 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +11 -11
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +24 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
- data/test/new_relic/rack/developer_mode_test.rb +13 -7
- data/test/new_relic/rack/error_collector_test.rb +74 -0
- data/test/new_relic/stats_test.rb +10 -0
- data/test/new_relic/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +47 -2
- data/test/new_relic/version_number_test.rb +32 -0
- data/test/script/build_test_gem.sh +9 -3
- data/test/script/ci.sh +108 -35
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +68 -18
- data/ui/helpers/developer_mode_helper.rb +21 -11
- data/ui/views/layouts/newrelic_default.rhtml +1 -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/show_sample.rhtml +1 -1
- data/ui/views/newrelic/threads.rhtml +2 -10
- data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
- metadata +191 -65
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/control/configuration.rb +0 -206
- data/lib/new_relic/control/logging_methods.rb +0 -143
- data/lib/new_relic/data_serialization.rb +0 -151
- data/test/new_relic/control/configuration_test.rb +0 -84
- data/test/new_relic/control/logging_methods_test.rb +0 -185
- data/test/new_relic/data_serialization_test.rb +0 -208
@@ -30,13 +30,14 @@ module NewRelic
|
|
30
30
|
# called when a transaction finishes, to add time to the
|
31
31
|
# instance variable accumulator. this is harvested when we send
|
32
32
|
# data to the server
|
33
|
-
def dispatcher_finish(end_time =
|
33
|
+
def dispatcher_finish(end_time = nil)
|
34
|
+
end_time ||= time_now
|
34
35
|
callers = Thread.current[:busy_entries] -= 1
|
35
36
|
# Ignore nested calls
|
36
37
|
return if callers > 0
|
37
38
|
@lock.synchronize do
|
38
39
|
if @entrypoint_stack.empty?
|
39
|
-
NewRelic::Agent.logger.
|
40
|
+
::NewRelic::Agent.logger.warn("Stack underflow tracking dispatcher entry and exit!\n #{caller.join(" \n")}")
|
40
41
|
else
|
41
42
|
@accumulator += (end_time - @entrypoint_stack.pop).to_f
|
42
43
|
end
|
@@ -56,15 +57,14 @@ module NewRelic
|
|
56
57
|
Thread.current[:busy_entries] = 0
|
57
58
|
@lock ||= Mutex.new
|
58
59
|
@accumulator = 0
|
59
|
-
@harvest_start =
|
60
|
+
@harvest_start = time_now
|
60
61
|
end
|
61
62
|
|
62
|
-
self.reset
|
63
63
|
|
64
64
|
# Called before uploading to to the server to collect current busy stats.
|
65
65
|
def harvest_busy
|
66
66
|
busy = 0
|
67
|
-
t0 =
|
67
|
+
t0 = time_now
|
68
68
|
@lock.synchronize do
|
69
69
|
busy = accumulator
|
70
70
|
@accumulator = 0
|
@@ -85,15 +85,23 @@ module NewRelic
|
|
85
85
|
|
86
86
|
busy = busy / time_window
|
87
87
|
|
88
|
-
instance_busy_stats.record_data_point busy
|
88
|
+
instance_busy_stats.record_data_point busy if Agent.config[:report_instance_busy]
|
89
89
|
@harvest_start = t0
|
90
90
|
end
|
91
|
+
|
91
92
|
private
|
93
|
+
|
94
|
+
# so we can stub Time.now only for the BusyCalculator in tests
|
95
|
+
def time_now
|
96
|
+
Time.now
|
97
|
+
end
|
98
|
+
|
92
99
|
def instance_busy_stats
|
93
100
|
# Late binding on the Instance/busy stats
|
94
101
|
NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'Instance/Busy'
|
95
102
|
end
|
96
103
|
|
104
|
+
self.reset
|
97
105
|
end
|
98
106
|
end
|
99
107
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'new_relic/agent/configuration/manager'
|
2
|
+
|
3
|
+
# The agent's configuration is accessed through a configuration object exposed
|
4
|
+
# by ::NewRelic::Agent.config. It provides a hash like interface to the
|
5
|
+
# agent's settings.
|
6
|
+
#
|
7
|
+
# For example:
|
8
|
+
# ::NewRelic::Agent.config[:'transaction_tracer.enabled']
|
9
|
+
# determines whether transaction tracing is enabled. String and symbol keys
|
10
|
+
# are treated indifferently and nested keys are collapsed and concatenated with
|
11
|
+
# a dot (i.e. {:a => {:b => 'c'} becomes { 'a.b' => 'c'}).
|
12
|
+
#
|
13
|
+
# The agent reads configuration from a variety of sources. These sources are
|
14
|
+
# modeled as a set of layers. The top layer has the highest priority. If the
|
15
|
+
# top layer does not contain the requested setting the config object will search
|
16
|
+
# through the subsequent layers returning the first value it finds.
|
17
|
+
#
|
18
|
+
# Configuration layers include EnvironmentSource (which reads settings from
|
19
|
+
# ENV), ServerSource (which reads Server Side Config from New Relic's servers),
|
20
|
+
# YamlSource (which reads from newrelic.yml), ManualSource (which reads
|
21
|
+
# arguments passed to NewRelic::Agent.manual_start or potentially other
|
22
|
+
# methods), and Defaults (which contains default settings).
|
23
|
+
#
|
24
|
+
module NewRelic
|
25
|
+
module Agent
|
26
|
+
module Configuration
|
27
|
+
# This can be mixed in with minimal impact to provide easy
|
28
|
+
# access to the config manager
|
29
|
+
module Instance
|
30
|
+
def config
|
31
|
+
@@manager ||= Manager.new
|
32
|
+
end
|
33
|
+
|
34
|
+
# for testing
|
35
|
+
def reset_config
|
36
|
+
@@manager = Manager.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class DottedHash < ::Hash
|
41
|
+
def initialize(hash)
|
42
|
+
self.merge!(dot_flattened(hash))
|
43
|
+
keys.each do |key|
|
44
|
+
self[(key.to_sym rescue key) || key] = delete(key)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def inspect
|
49
|
+
"#<#{self.class.name}:#{object_id} #{super}>"
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_hash
|
53
|
+
{}.replace(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
# turns {'a' => {'b' => 'c'}} into {'a.b' => 'c'}
|
58
|
+
def dot_flattened(nested_hash, names=[], result={})
|
59
|
+
nested_hash.each do |key, val|
|
60
|
+
next if val == nil
|
61
|
+
if val.respond_to?(:has_key?)
|
62
|
+
dot_flattened(val, names + [key], result)
|
63
|
+
else
|
64
|
+
result[(names + [key]).join('.')] = val
|
65
|
+
end
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ManualSource < DottedHash; end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
module Configuration
|
4
|
+
DEFAULTS = {
|
5
|
+
:config_path => Proc.new {
|
6
|
+
# Check a sequence of file locations for newrelic.yml
|
7
|
+
files = []
|
8
|
+
files << File.join("config","newrelic.yml")
|
9
|
+
files << File.join("newrelic.yml")
|
10
|
+
if ENV["HOME"]
|
11
|
+
files << File.join(ENV["HOME"], ".newrelic", "newrelic.yml")
|
12
|
+
files << File.join(ENV["HOME"], "newrelic.yml")
|
13
|
+
end
|
14
|
+
files.detect do |file|
|
15
|
+
File.expand_path(file) if File.exists? file
|
16
|
+
end
|
17
|
+
},
|
18
|
+
:app_name => Proc.new { NewRelic::Control.instance.env },
|
19
|
+
:dispatcher => Proc.new { NewRelic::Control.instance.local_env.discovered_dispatcher },
|
20
|
+
:framework => Proc.new do
|
21
|
+
case
|
22
|
+
when defined?(::NewRelic::TEST) then :test
|
23
|
+
when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
|
24
|
+
when defined?(::Rails)
|
25
|
+
case Rails::VERSION::MAJOR
|
26
|
+
when 0..2
|
27
|
+
:rails
|
28
|
+
when 3
|
29
|
+
:rails3
|
30
|
+
when 4
|
31
|
+
:rails4
|
32
|
+
else
|
33
|
+
Agent.logger.error "Detected unsupported Rails version #{Rails::VERSION::STRING}"
|
34
|
+
end
|
35
|
+
when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
|
36
|
+
when defined?(::NewRelic::IA) then :external
|
37
|
+
else :ruby
|
38
|
+
end
|
39
|
+
end,
|
40
|
+
:enabled => true,
|
41
|
+
:monitor_mode => Proc.new { self[:enabled] },
|
42
|
+
:agent_enabled => Proc.new do
|
43
|
+
self[:enabled] &&
|
44
|
+
(self[:developer_mode] || self[:monitor_mode] || self[:monitor_daemons]) &&
|
45
|
+
!!NewRelic::Agent.config[:dispatcher]
|
46
|
+
end,
|
47
|
+
:developer_mode => Proc.new { self[:developer] },
|
48
|
+
:developer => false,
|
49
|
+
:apdex_t => 0.5,
|
50
|
+
:monitor_daemons => false,
|
51
|
+
:multi_homed => false,
|
52
|
+
:high_security => false,
|
53
|
+
|
54
|
+
:host => 'collector.newrelic.com',
|
55
|
+
:api_host => 'rpm.newrelic.com',
|
56
|
+
:port => Proc.new { self[:ssl] ? 443 : 80 },
|
57
|
+
:api_port => Proc.new { self[:port] },
|
58
|
+
:ssl => false,
|
59
|
+
:verify_certificate => false,
|
60
|
+
:sync_startup => false,
|
61
|
+
:send_data_on_exit => true,
|
62
|
+
:post_size_limit => 2 * 1024 * 1024, # 2 megs
|
63
|
+
:timeout => 2 * 60, # 2 minutes
|
64
|
+
:force_send => false,
|
65
|
+
:send_environment_info => true,
|
66
|
+
:start_channel_listener => false,
|
67
|
+
:data_report_period => 60,
|
68
|
+
:keep_retrying => true,
|
69
|
+
:report_instance_busy => true,
|
70
|
+
|
71
|
+
:log_file_name => 'newrelic_agent.log',
|
72
|
+
:log_file_path => 'log/',
|
73
|
+
:log_level => 'info',
|
74
|
+
|
75
|
+
:'audit_log.enabled' => false,
|
76
|
+
:'audit_log.path' => Proc.new {
|
77
|
+
File.join(self[:log_file_path], 'newrelic_audit.log')
|
78
|
+
},
|
79
|
+
|
80
|
+
:disable_samplers => false,
|
81
|
+
:disable_resque => false,
|
82
|
+
:disable_dj => false,
|
83
|
+
:disable_view_instrumentation => false,
|
84
|
+
:disable_backtrace_cleanup => false,
|
85
|
+
:skip_ar_instrumentation => false,
|
86
|
+
:disable_activerecord_instrumentation => Proc.new { self[:skip_ar_instrumentation] },
|
87
|
+
:disable_memcache_instrumentation => false,
|
88
|
+
:disable_mobile_headers => true,
|
89
|
+
|
90
|
+
:capture_memcache_keys => false,
|
91
|
+
:textmate => false,
|
92
|
+
|
93
|
+
:'transaction_tracer.enabled' => true,
|
94
|
+
:'transaction_tracer.transaction_threshold' => Proc.new { self[:apdex_t] * 4 },
|
95
|
+
:'transaction_tracer.stack_trace_threshold' => 0.5,
|
96
|
+
:'transaction_tracer.explain_threshold' => 0.5,
|
97
|
+
:'transaction_tracer.explain_enabled' => true,
|
98
|
+
:'transaction_tracer.record_sql' => 'obfuscated',
|
99
|
+
:'transaction_tracer.limit_segments' => 4000,
|
100
|
+
:'transaction_tracer.random_sample' => false,
|
101
|
+
:sample_rate => 10,
|
102
|
+
|
103
|
+
:'slow_sql.enabled' => Proc.new { self[:'transaction_tracer.enabled'] },
|
104
|
+
:'slow_sql.stack_trace_threshold' => Proc.new { self[:'transaction_tracer.stack_trace_threshold'] },
|
105
|
+
:'slow_sql.explain_threshold' => Proc.new { self[:'transaction_tracer.explain_threshold'] },
|
106
|
+
:'slow_sql.explain_enabled' => Proc.new { self[:'transaction_tracer.explain_enabled'] },
|
107
|
+
:'slow_sql.record_sql' => Proc.new { self[:'transaction_tracer.record_sql'] },
|
108
|
+
|
109
|
+
:'error_collector.enabled' => true,
|
110
|
+
:'error_collector.capture_source' => true,
|
111
|
+
:'error_collector.ignore_errors' => 'ActionController::RoutingError',
|
112
|
+
|
113
|
+
:'rum.enabled' => true,
|
114
|
+
:'rum.jsonp' => true,
|
115
|
+
:'rum.load_episodes_file' => true,
|
116
|
+
:'browser_monitoring.auto_instrument' => Proc.new { self[:'rum.enabled'] },
|
117
|
+
|
118
|
+
:'cross_process.enabled' => true,
|
119
|
+
|
120
|
+
:'thread_profiler.enabled' => Proc.new { NewRelic::Agent::ThreadProfiler.is_supported? },
|
121
|
+
|
122
|
+
:marshaller => Proc.new { NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported? ? 'json' : 'pruby' }
|
123
|
+
}.freeze
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
module Configuration
|
4
|
+
class EnvironmentSource < DottedHash
|
5
|
+
def initialize
|
6
|
+
string_map = {
|
7
|
+
'NRCONFIG' => :config_path,
|
8
|
+
'NEW_RELIC_LICENSE_KEY' => :license_key,
|
9
|
+
'NEWRELIC_LICENSE_KEY' => :license_key,
|
10
|
+
'NEW_RELIC_APP_NAME' => :app_name,
|
11
|
+
'NEWRELIC_APP_NAME' => :app_name,
|
12
|
+
'NEW_RELIC_HOST' => :host,
|
13
|
+
'NEW_RELIC_PORT' => :port
|
14
|
+
}.each do |key, val|
|
15
|
+
self[val] = ENV[key] if ENV[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
symbol_map = {
|
19
|
+
'NEW_RELIC_DISPATCHER' => :dispatcher,
|
20
|
+
'NEWRELIC_DISPATCHER' => :dispatcher,
|
21
|
+
'NEW_RELIC_FRAMEWORK' => :framework,
|
22
|
+
'NEWRELIC_FRAMEWORK' => :framework
|
23
|
+
}.each do |key, val|
|
24
|
+
self[val] = ENV[key].intern if ENV[key]
|
25
|
+
end
|
26
|
+
|
27
|
+
boolean_map = {
|
28
|
+
'NEWRELIC_ENABLE' => :agent_enabled
|
29
|
+
}.each do |key, val|
|
30
|
+
if ENV[key].to_s =~ /false|off|no/i
|
31
|
+
self[val] = false
|
32
|
+
elsif ENV[key] != nil
|
33
|
+
self[val] = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if ENV['NEW_RELIC_LOG']
|
38
|
+
if ENV['NEW_RELIC_LOG'].upcase == 'STDOUT'
|
39
|
+
self[:log_file_path] = self[:log_file_name] = 'STDOUT'
|
40
|
+
else
|
41
|
+
self[:log_file_path] = File.dirname(ENV['NEW_RELIC_LOG'])
|
42
|
+
self[:log_file_name] = File.basename(ENV['NEW_RELIC_LOG'])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'new_relic/agent/configuration/defaults'
|
3
|
+
require 'new_relic/agent/configuration/mask_defaults'
|
4
|
+
require 'new_relic/agent/configuration/yaml_source'
|
5
|
+
require 'new_relic/agent/configuration/server_source'
|
6
|
+
require 'new_relic/agent/configuration/environment_source'
|
7
|
+
|
8
|
+
module NewRelic
|
9
|
+
module Agent
|
10
|
+
module Configuration
|
11
|
+
class Manager
|
12
|
+
extend Forwardable
|
13
|
+
def_delegators :@cache, :[], :has_key?
|
14
|
+
attr_reader :config_stack # mainly for testing
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@config_stack = [ EnvironmentSource.new, DEFAULTS ]
|
18
|
+
@cache = Hash.new {|hash,key| hash[key] = self.fetch(key) }
|
19
|
+
@callbacks = Hash.new {|hash,key| hash[key] = [] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def apply_config(source, level=0)
|
23
|
+
invoke_callbacks(:add, source)
|
24
|
+
@config_stack.insert(level, source.freeze)
|
25
|
+
reset_cache
|
26
|
+
log_config(:add, source)
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_config(source=nil)
|
30
|
+
if block_given?
|
31
|
+
@config_stack.delete_if {|c| yield c }
|
32
|
+
else
|
33
|
+
@config_stack.delete(source)
|
34
|
+
end
|
35
|
+
reset_cache
|
36
|
+
invoke_callbacks(:remove, source)
|
37
|
+
log_config(:remove, source)
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_or_add_config(source, level=0)
|
41
|
+
idx = @config_stack.map{|s| s.class}.index(source.class)
|
42
|
+
@config_stack.delete_at(idx) if idx
|
43
|
+
apply_config(source, idx || level)
|
44
|
+
end
|
45
|
+
|
46
|
+
def source(key)
|
47
|
+
@config_stack.each do |config|
|
48
|
+
if config.respond_to?(key.to_sym) || config.has_key?(key.to_sym)
|
49
|
+
return config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def fetch(key)
|
55
|
+
@config_stack.each do |config|
|
56
|
+
next unless config
|
57
|
+
accessor = key.to_sym
|
58
|
+
if config.has_key?(accessor)
|
59
|
+
if config[accessor].respond_to?(:call)
|
60
|
+
return instance_eval(&config[accessor])
|
61
|
+
else
|
62
|
+
return config[accessor]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def register_callback(key, &proc)
|
70
|
+
@callbacks[key] << proc
|
71
|
+
proc.call(@cache[key])
|
72
|
+
end
|
73
|
+
|
74
|
+
def invoke_callbacks(direction, source)
|
75
|
+
return unless source
|
76
|
+
source.keys.each do |key|
|
77
|
+
if @cache[key] != source[key]
|
78
|
+
@callbacks[key].each do |proc|
|
79
|
+
if direction == :add
|
80
|
+
proc.call(source[key])
|
81
|
+
else
|
82
|
+
proc.call(@cache[key])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def flattened
|
90
|
+
@config_stack.reverse.inject({}) do |flat,layer|
|
91
|
+
thawed_layer = layer.dup
|
92
|
+
thawed_layer.each do |k,v|
|
93
|
+
begin
|
94
|
+
thawed_layer[k] = instance_eval(&v) if v.respond_to?(:call)
|
95
|
+
rescue => e
|
96
|
+
::NewRelic::Agent.logger.debug("#{e.class.name} : #{e.message} - when accessing config key #{k}")
|
97
|
+
thawed_layer[k] = nil
|
98
|
+
end
|
99
|
+
thawed_layer.delete(:config)
|
100
|
+
end
|
101
|
+
flat.merge(thawed_layer)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def apply_mask(hash)
|
106
|
+
MASK_DEFAULTS. \
|
107
|
+
select {|_, proc| proc.call}. \
|
108
|
+
each {|key, _| hash.delete(key) }
|
109
|
+
hash
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_collector_hash
|
113
|
+
DottedHash.new(apply_mask(flattened)).to_hash
|
114
|
+
end
|
115
|
+
|
116
|
+
def app_names
|
117
|
+
case self[:app_name]
|
118
|
+
when Array then self[:app_name]
|
119
|
+
when String then self[:app_name].split(';')
|
120
|
+
else []
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def reset_cache
|
125
|
+
@cache = Hash.new {|hash,key| hash[key] = self.fetch(key) }
|
126
|
+
end
|
127
|
+
|
128
|
+
def log_config(direction, source)
|
129
|
+
::NewRelic::Agent.logger.debug(
|
130
|
+
"Updating config (#{direction}) from #{source.class}. Results:",
|
131
|
+
flattened.inspect)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|