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
@@ -1,40 +0,0 @@
|
|
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
|
@@ -1,206 +0,0 @@
|
|
1
|
-
module NewRelic
|
2
|
-
class Control
|
3
|
-
# used to contain methods to look up settings from the
|
4
|
-
# configuration located in newrelic.yml
|
5
|
-
module Configuration
|
6
|
-
def settings
|
7
|
-
unless @settings
|
8
|
-
@settings = (@yaml && merge_defaults(@yaml[env])) || {}
|
9
|
-
# At the time we bind the settings, we also need to run this little piece
|
10
|
-
# of magic which allows someone to augment the id with the app name, necessary
|
11
|
-
if self['multi_homed'] && app_names.size > 0
|
12
|
-
if @local_env.dispatcher_instance_id
|
13
|
-
@local_env.dispatcher_instance_id << ":#{app_names.first}"
|
14
|
-
else
|
15
|
-
@local_env.dispatcher_instance_id = app_names.first
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
@settings
|
21
|
-
end
|
22
|
-
|
23
|
-
def merge_defaults(settings_hash)
|
24
|
-
s = {
|
25
|
-
'host' => 'collector.newrelic.com',
|
26
|
-
'ssl' => false,
|
27
|
-
'log_level' => 'info',
|
28
|
-
'apdex_t' => 0.5
|
29
|
-
}
|
30
|
-
s.merge! settings_hash if settings_hash
|
31
|
-
# monitor_daemons replaced with agent_enabled
|
32
|
-
s['agent_enabled'] = s.delete('monitor_daemons') if s['agent_enabled'].nil? && s.include?('monitor_daemons')
|
33
|
-
s
|
34
|
-
end
|
35
|
-
|
36
|
-
# Merge the given options into the config options.
|
37
|
-
# They might be a nested hash
|
38
|
-
def merge_options(options, hash=self)
|
39
|
-
options.each do |key, val|
|
40
|
-
case
|
41
|
-
when key == :config then next
|
42
|
-
when val.is_a?(Hash)
|
43
|
-
merge_options(val, hash[key.to_s] ||= {})
|
44
|
-
when val.nil?
|
45
|
-
hash.delete(key.to_s)
|
46
|
-
else
|
47
|
-
hash[key.to_s] = val
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def merge_server_side_config(data)
|
53
|
-
remove_server_controlled_configs
|
54
|
-
config = Hash.new
|
55
|
-
data.each_pair do |key, value|
|
56
|
-
if key.include?('.')
|
57
|
-
key = key.split('.')
|
58
|
-
config[key.first] ||= Hash.new
|
59
|
-
config[key.first][key[1]] = value
|
60
|
-
else
|
61
|
-
config[key] = value
|
62
|
-
end
|
63
|
-
end
|
64
|
-
merge_options(config)
|
65
|
-
end
|
66
|
-
|
67
|
-
def remove_server_controlled_configs
|
68
|
-
settings.delete('transaction_tracer')
|
69
|
-
settings.delete('slow_sql')
|
70
|
-
settings.delete('error_collector')
|
71
|
-
settings.delete('capture_params')
|
72
|
-
end
|
73
|
-
|
74
|
-
def [](key)
|
75
|
-
fetch(key)
|
76
|
-
end
|
77
|
-
|
78
|
-
def []=(key, value)
|
79
|
-
settings[key] = value
|
80
|
-
end
|
81
|
-
|
82
|
-
def fetch(key, default=nil)
|
83
|
-
settings.fetch(key, default)
|
84
|
-
end
|
85
|
-
|
86
|
-
def apdex_t
|
87
|
-
# Always initialized with a default
|
88
|
-
@apdex_t_float ||= fetch('apdex_t').to_f
|
89
|
-
end
|
90
|
-
|
91
|
-
def license_key
|
92
|
-
env_setting = ENV['NEW_RELIC_LICENSE_KEY'] || ENV['NEWRELIC_LICENSE_KEY']
|
93
|
-
fetch('license_key', env_setting)
|
94
|
-
end
|
95
|
-
|
96
|
-
def capture_params
|
97
|
-
fetch('capture_params')
|
98
|
-
end
|
99
|
-
|
100
|
-
# True if we are sending data to the server, monitoring production
|
101
|
-
def monitor_mode?
|
102
|
-
fetch('monitor_mode', fetch('enabled'))
|
103
|
-
end
|
104
|
-
|
105
|
-
# True if we are capturing data and displaying in /newrelic
|
106
|
-
def developer_mode?
|
107
|
-
fetch('developer_mode', fetch('developer'))
|
108
|
-
end
|
109
|
-
|
110
|
-
# whether we should install the
|
111
|
-
# NewRelic::Rack::BrowserMonitoring middleware automatically on
|
112
|
-
# Rails applications
|
113
|
-
def browser_monitoring_auto_instrument?
|
114
|
-
fetch('browser_monitoring', {}).fetch('auto_instrument', true)
|
115
|
-
end
|
116
|
-
|
117
|
-
def multi_threaded?
|
118
|
-
fetch('multi_threaded')
|
119
|
-
end
|
120
|
-
|
121
|
-
def disable_serialization?
|
122
|
-
fetch('disable_serialization', !DependencyDetection.installed?(:resque))
|
123
|
-
end
|
124
|
-
def disable_serialization=(b)
|
125
|
-
self['disable_serialization'] = b
|
126
|
-
end
|
127
|
-
|
128
|
-
# True if we should view files in textmate
|
129
|
-
def use_textmate?
|
130
|
-
fetch('textmate')
|
131
|
-
end
|
132
|
-
|
133
|
-
# defaults to 2MiB
|
134
|
-
def post_size_limit
|
135
|
-
fetch('post_size_limit', 2 * 1024 * 1024)
|
136
|
-
end
|
137
|
-
|
138
|
-
# Configuration option of the same name to indicate that we should connect
|
139
|
-
# to New Relic synchronously on startup. This means when the agent is loaded it
|
140
|
-
# won't return without trying to set up the server connection at least once
|
141
|
-
# which can make startup take longer. Defaults to false.
|
142
|
-
def sync_startup
|
143
|
-
fetch('sync_startup', false)
|
144
|
-
end
|
145
|
-
|
146
|
-
# Configuration option of the same name to indicate that we should flush
|
147
|
-
# data to the server on exiting. Defaults to true.
|
148
|
-
def send_data_on_exit
|
149
|
-
fetch('send_data_on_exit', true)
|
150
|
-
end
|
151
|
-
|
152
|
-
def dispatcher_instance_id
|
153
|
-
self['dispatcher_instance_id'] || @local_env.dispatcher_instance_id
|
154
|
-
end
|
155
|
-
|
156
|
-
def dispatcher
|
157
|
-
(self['dispatcher'] && self['dispatcher'].to_sym) || @local_env.dispatcher
|
158
|
-
end
|
159
|
-
def app_names
|
160
|
-
case self['app_name']
|
161
|
-
when Array then self['app_name']
|
162
|
-
when String then self['app_name'].split(';')
|
163
|
-
else [ env ]
|
164
|
-
end
|
165
|
-
end
|
166
|
-
def validate_seed
|
167
|
-
self['validate_seed'] || ENV['NR_VALIDATE_SEED']
|
168
|
-
end
|
169
|
-
def validate_token
|
170
|
-
self['validate_token'] || ENV['NR_VALIDATE_TOKEN']
|
171
|
-
end
|
172
|
-
|
173
|
-
def use_ssl?
|
174
|
-
@use_ssl = fetch('ssl', false) unless @use_ssl
|
175
|
-
@use_ssl
|
176
|
-
end
|
177
|
-
|
178
|
-
def log_file_path
|
179
|
-
fetch('log_file_path', 'log/')
|
180
|
-
end
|
181
|
-
|
182
|
-
# only verify certificates if you're very sure you want this
|
183
|
-
# level of security, it includes possibly app-crashing dns
|
184
|
-
# lookups every connection to the server
|
185
|
-
def verify_certificate?
|
186
|
-
unless @verify_certificate
|
187
|
-
unless use_ssl?
|
188
|
-
@verify_certificate = false
|
189
|
-
else
|
190
|
-
@verify_certificate = fetch('verify_certificate', false)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
@verify_certificate
|
194
|
-
end
|
195
|
-
|
196
|
-
def disable_backtrace_cleanup?
|
197
|
-
fetch('disable_backtrace_cleanup')
|
198
|
-
end
|
199
|
-
|
200
|
-
def has_slow_sql_config?
|
201
|
-
self['slow_sql'] && self['slow_sql'].has_key?('enabled')
|
202
|
-
end
|
203
|
-
end
|
204
|
-
include Configuration
|
205
|
-
end
|
206
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
|
2
|
-
module NewRelic
|
3
|
-
class Control
|
4
|
-
# Contains methods that relate to locating, creating, and writing
|
5
|
-
# to the log file and/or standard out
|
6
|
-
module LoggingMethods
|
7
|
-
|
8
|
-
attr_accessor :log_file
|
9
|
-
|
10
|
-
# returns either the log set up with setup_log or else a new
|
11
|
-
# logger pointing to standard out, if we're trying to log before
|
12
|
-
# a log exists
|
13
|
-
def log
|
14
|
-
if !@log
|
15
|
-
l = Logger.new(STDOUT)
|
16
|
-
l.level = Logger::INFO
|
17
|
-
return l
|
18
|
-
end
|
19
|
-
@log
|
20
|
-
end
|
21
|
-
|
22
|
-
# send the given message to STDOUT so that it shows
|
23
|
-
# up in the console. This should be used for important informational messages at boot.
|
24
|
-
# The to_stdout may be implemented differently by different config subclasses.
|
25
|
-
# This will NOT print anything if tracers are not enabled
|
26
|
-
def log!(msg, level=:info)
|
27
|
-
to_stdout msg
|
28
|
-
return unless should_log?
|
29
|
-
log.send level, msg if @log
|
30
|
-
end
|
31
|
-
|
32
|
-
# true if the agent has settings, and the agent is enabled,
|
33
|
-
# otherwise false
|
34
|
-
def should_log?
|
35
|
-
@settings && agent_enabled?
|
36
|
-
end
|
37
|
-
|
38
|
-
# set the log level as specified in the config file
|
39
|
-
#
|
40
|
-
# Possible values are from the Logger class: debug, info, warn,
|
41
|
-
#error, and fatal
|
42
|
-
# Defaults to info
|
43
|
-
def set_log_level!(logger)
|
44
|
-
case fetch("log_level","info").downcase
|
45
|
-
when "debug" then logger.level = Logger::DEBUG
|
46
|
-
when "info" then logger.level = Logger::INFO
|
47
|
-
when "warn" then logger.level = Logger::WARN
|
48
|
-
when "error" then logger.level = Logger::ERROR
|
49
|
-
when "fatal" then logger.level = Logger::FATAL
|
50
|
-
else logger.level = Logger::INFO
|
51
|
-
end
|
52
|
-
logger
|
53
|
-
end
|
54
|
-
|
55
|
-
# patches the logger's format_message method to change the format just for our logger
|
56
|
-
def set_log_format!(logger)
|
57
|
-
def logger.format_message(severity, timestamp, progname, msg)
|
58
|
-
prefix = @logdev.dev == STDOUT ? '** [NewRelic]' : ''
|
59
|
-
prefix + "[#{timestamp.strftime("%m/%d/%y %H:%M:%S %z")} #{Socket.gethostname} (#{$$})] #{severity} : #{msg}\n"
|
60
|
-
end
|
61
|
-
logger
|
62
|
-
end
|
63
|
-
|
64
|
-
# Create the logger using the configuration variables
|
65
|
-
#
|
66
|
-
# Control subclasses may override this, but it can be called multiple times.
|
67
|
-
def setup_log
|
68
|
-
if log_to_stdout?
|
69
|
-
@log = Logger.new(STDOUT)
|
70
|
-
else
|
71
|
-
@log_file = "#{log_path}/#{log_file_name}"
|
72
|
-
@log = Logger.new(@log_file) rescue nil
|
73
|
-
@log ||= Logger.new(STDOUT) # failsafe to STDOUT
|
74
|
-
end
|
75
|
-
|
76
|
-
if @log
|
77
|
-
set_log_format!(@log)
|
78
|
-
set_log_level!(@log)
|
79
|
-
end
|
80
|
-
# note this is not the variable from above - it is the `log`
|
81
|
-
# method, which returns a default logger if none is setup
|
82
|
-
# above
|
83
|
-
log
|
84
|
-
end
|
85
|
-
|
86
|
-
# simply puts a message to standard out, prepended with the
|
87
|
-
# '** [NewRelic]' sigil to make sure people know where the message
|
88
|
-
# comes from. This should be used sparingly
|
89
|
-
def to_stdout(msg)
|
90
|
-
STDOUT.puts "** [NewRelic] " + msg
|
91
|
-
end
|
92
|
-
|
93
|
-
# Sets up and caches the log path, attempting to create it if it
|
94
|
-
# does not exist. If it does not succeed, it prints an
|
95
|
-
# error and returns nil.
|
96
|
-
# This comes from the configuration variable 'log_file_path' in the configuration file.
|
97
|
-
def log_path
|
98
|
-
return @log_path if @log_path
|
99
|
-
if log_to_stdout?
|
100
|
-
@log_path = nil
|
101
|
-
else
|
102
|
-
if ENV['NEW_RELIC_LOG']
|
103
|
-
log_path_setting = File.dirname(ENV['NEW_RELIC_LOG'])
|
104
|
-
else
|
105
|
-
log_path_setting = fetch('log_file_path', 'log')
|
106
|
-
end
|
107
|
-
@log_path = find_or_create_file_path(log_path_setting)
|
108
|
-
log!("Error creating log directory #{log_path_setting}, using standard out for logging.", :warn) unless @log_path
|
109
|
-
end
|
110
|
-
@log_path
|
111
|
-
end
|
112
|
-
|
113
|
-
def find_or_create_file_path(path_setting)
|
114
|
-
for abs_path in [ File.expand_path(path_setting),
|
115
|
-
File.expand_path(File.join(root, path_setting)) ] do
|
116
|
-
if File.directory?(abs_path) || (Dir.mkdir(abs_path) rescue nil)
|
117
|
-
return abs_path[%r{^(.*?)/?$}]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
nil
|
121
|
-
end
|
122
|
-
|
123
|
-
def log_to_stdout?
|
124
|
-
return true if @stdout
|
125
|
-
destination = ENV['NEW_RELIC_LOG'] || fetch('log_file_path', 'log')
|
126
|
-
if destination.upcase == 'STDOUT'
|
127
|
-
@stdout = true
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Retrieves the log file's name from the config file option
|
132
|
-
#'log_file_name', defaulting to 'newrelic_agent.log'
|
133
|
-
def log_file_name
|
134
|
-
if ENV['NEW_RELIC_LOG']
|
135
|
-
File.basename(ENV['NEW_RELIC_LOG'])
|
136
|
-
else
|
137
|
-
fetch('log_file_name', 'newrelic_agent.log')
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
include LoggingMethods
|
142
|
-
end
|
143
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'new_relic/language_support'
|
3
|
-
|
4
|
-
module NewRelic
|
5
|
-
# Handles serialization of data to disk, to save on contacting the
|
6
|
-
# server. Lowers both server and client overhead, if the disk is not overloaded
|
7
|
-
class DataSerialization
|
8
|
-
include NewRelic::LanguageSupport::DataSerialization
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
# Check whether the store is too large, too old, or the
|
12
|
-
# pid file is too old. If so, we should send the data
|
13
|
-
# right away. If not, we presumably store it for later sending
|
14
|
-
# (handled elsewhere)
|
15
|
-
def should_send_data?
|
16
|
-
NewRelic::Control.instance.disable_serialization? || store_too_large? ||
|
17
|
-
store_too_old? || pid_too_old? ||
|
18
|
-
NewRelic::LanguageSupport.using_version?('1.8.6')
|
19
|
-
rescue => e
|
20
|
-
NewRelic::Control.instance.disable_serialization = true
|
21
|
-
NewRelic::Control.instance.log.warn("Disabling serialization: #{e.message}")
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
# A combined locked read/write from the store file - reduces
|
26
|
-
# contention by not acquiring the lock and file handle twice
|
27
|
-
def read_and_write_to_file
|
28
|
-
with_locked_store do |f|
|
29
|
-
result = (yield get_data_from_file(f))
|
30
|
-
f.rewind
|
31
|
-
f.truncate(0)
|
32
|
-
write_contents_nonblockingly(f, dump(result)) if result
|
33
|
-
end
|
34
|
-
rescue Errno::ENOENT => e
|
35
|
-
NewRelic::Control.instance.log.warn(e.message)
|
36
|
-
end
|
37
|
-
|
38
|
-
# touches the age file that determines whether we should send
|
39
|
-
# data now or not
|
40
|
-
def update_last_sent!
|
41
|
-
FileUtils.touch(pid_file_path)
|
42
|
-
end
|
43
|
-
|
44
|
-
def pid_too_old?
|
45
|
-
return true unless File.exists?(pid_file_path)
|
46
|
-
age = (Time.now.to_i - File.mtime(pid_file_path).to_i)
|
47
|
-
NewRelic::Control.instance.log.debug("Pid was #{age} seconds old, sending data") if age > 60
|
48
|
-
age > 60
|
49
|
-
end
|
50
|
-
|
51
|
-
def store_too_old?
|
52
|
-
return true unless File.exists?(file_path)
|
53
|
-
age = (Time.now.to_i - File.mtime(file_path).to_i)
|
54
|
-
NewRelic::Control.instance.log.debug("Store was #{age} seconds old, sending data") if age > 60
|
55
|
-
age > 50
|
56
|
-
end
|
57
|
-
|
58
|
-
def store_too_large?
|
59
|
-
return true unless File.exists?(file_path)
|
60
|
-
size = File.size(file_path) > max_size
|
61
|
-
NewRelic::Control.instance.log.debug("Store was oversize, sending data") if size
|
62
|
-
size
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def open_arguments
|
68
|
-
if defined?(Encoding)
|
69
|
-
[file_path, File::RDWR | File::CREAT, {:internal_encoding => nil}]
|
70
|
-
else
|
71
|
-
[file_path, File::RDWR | File::CREAT]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def with_locked_store
|
76
|
-
File.open(*open_arguments) do |f|
|
77
|
-
f.flock(File::LOCK_EX)
|
78
|
-
begin
|
79
|
-
yield(f)
|
80
|
-
ensure
|
81
|
-
f.flock(File::LOCK_UN)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
rescue => e
|
85
|
-
NewRelic::Control.instance.log.error("Error serializing data to disk: #{e.inspect}")
|
86
|
-
NewRelic::Control.instance.log.debug(e.backtrace.split("\n"))
|
87
|
-
# re-raise so that serialization will be disabled higher up the stack
|
88
|
-
raise e
|
89
|
-
end
|
90
|
-
|
91
|
-
def get_data_from_file(f)
|
92
|
-
data = read_until_eof_error(f)
|
93
|
-
result = load(data)
|
94
|
-
f.truncate(0)
|
95
|
-
result
|
96
|
-
end
|
97
|
-
|
98
|
-
def write_contents_nonblockingly(f, string)
|
99
|
-
result = 0
|
100
|
-
while (result < string.length)
|
101
|
-
result += f.write_nonblock(string)
|
102
|
-
end
|
103
|
-
rescue Errno::EAGAIN, Errno::EINTR
|
104
|
-
IO.select(nil, [f])
|
105
|
-
retry
|
106
|
-
end
|
107
|
-
|
108
|
-
def read_until_eof_error(f)
|
109
|
-
accumulator = ""
|
110
|
-
while(true)
|
111
|
-
accumulator << f.read_nonblock(10_000)
|
112
|
-
end
|
113
|
-
rescue Errno::EAGAIN, Errno::EINTR
|
114
|
-
IO.select([f])
|
115
|
-
retry
|
116
|
-
rescue EOFError
|
117
|
-
accumulator
|
118
|
-
end
|
119
|
-
|
120
|
-
def max_size
|
121
|
-
10_000
|
122
|
-
end
|
123
|
-
|
124
|
-
def dump(object)
|
125
|
-
Marshal.dump(object.clone)
|
126
|
-
end
|
127
|
-
|
128
|
-
def load(dump)
|
129
|
-
if dump.respond_to?(:size) && dump.size == 0
|
130
|
-
NewRelic::Control.instance.log.debug("Spool file empty.")
|
131
|
-
return nil
|
132
|
-
end
|
133
|
-
Marshal.load(dump)
|
134
|
-
rescue ArgumentError, TypeError => e
|
135
|
-
NewRelic::Control.instance.log.error("Error loading data from newrelic_agent_store.db: #{e.inspect}")
|
136
|
-
NewRelic::Control.instance.log.debug(e.backtrace.inspect)
|
137
|
-
nil
|
138
|
-
end
|
139
|
-
|
140
|
-
def file_path
|
141
|
-
"#{NewRelic::Control.instance.log_path}/newrelic_agent_store.db"
|
142
|
-
end
|
143
|
-
|
144
|
-
def pid_file_path
|
145
|
-
"#{NewRelic::Control.instance.log_path}/newrelic_agent_store.pid"
|
146
|
-
end
|
147
|
-
end
|
148
|
-
extend ClassMethods
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|