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,89 @@
|
|
1
|
+
require 'thread'
|
2
|
+
module NewRelic
|
3
|
+
module Agent
|
4
|
+
|
5
|
+
# A worker loop executes a set of registered tasks on a single thread.
|
6
|
+
# A task is a proc or block with a specified call period in seconds.
|
7
|
+
class WorkerLoop
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@log = log
|
11
|
+
@should_run = true
|
12
|
+
@next_invocation_time = Time.now
|
13
|
+
@period = 60.0
|
14
|
+
end
|
15
|
+
|
16
|
+
# returns a class-level memoized mutex to make sure we don't run overlapping
|
17
|
+
def lock
|
18
|
+
@@lock ||= Mutex.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# a helper to access the NewRelic::Control.instance.log
|
22
|
+
def log
|
23
|
+
NewRelic::Control.instance.log
|
24
|
+
end
|
25
|
+
|
26
|
+
# Run infinitely, calling the registered tasks at their specified
|
27
|
+
# call periods. The caller is responsible for creating the thread
|
28
|
+
# that runs this worker loop. This will run the task immediately.
|
29
|
+
def run(period=nil, &block)
|
30
|
+
@period = period if period
|
31
|
+
@next_invocation_time = (Time.now + @period)
|
32
|
+
@task = block
|
33
|
+
while keep_running do
|
34
|
+
now = Time.now
|
35
|
+
while now < @next_invocation_time
|
36
|
+
# sleep until this next task's scheduled invocation time
|
37
|
+
sleep_time = @next_invocation_time - now
|
38
|
+
sleep sleep_time if sleep_time > 0
|
39
|
+
now = Time.now
|
40
|
+
end
|
41
|
+
run_task if keep_running
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# a simple accessor for @should_run
|
46
|
+
def keep_running
|
47
|
+
@should_run
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets @should_run to false. Returns false
|
51
|
+
def stop
|
52
|
+
@should_run = false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Executes the block given to the worker loop, and handles many
|
56
|
+
# possible errors. Also updates the execution time so that the
|
57
|
+
# next run occurs on schedule, even if we execute at some odd time
|
58
|
+
def run_task
|
59
|
+
begin
|
60
|
+
lock.synchronize do
|
61
|
+
@task.call
|
62
|
+
end
|
63
|
+
rescue ServerError => e
|
64
|
+
log.debug "Server Error: #{e}"
|
65
|
+
rescue NewRelic::Agent::ForceRestartException, NewRelic::Agent::ForceDisconnectException
|
66
|
+
# blow out the loop
|
67
|
+
raise
|
68
|
+
rescue RuntimeError => e
|
69
|
+
# This is probably a server error which has been logged in the server along
|
70
|
+
# with your account name.
|
71
|
+
log.error "Error running task in worker loop, likely a server error (#{e})"
|
72
|
+
log.debug e.backtrace.join("\n")
|
73
|
+
rescue Timeout::Error, NewRelic::Agent::ServerConnectionException
|
74
|
+
# Want to ignore these because they are handled already
|
75
|
+
rescue SystemExit, NoMemoryError, SignalException
|
76
|
+
raise
|
77
|
+
rescue => e
|
78
|
+
# Don't blow out the stack for anything that hasn't already propagated
|
79
|
+
log.error "Error running task in Agent Worker Loop '#{e}': #{e.backtrace.first}"
|
80
|
+
log.debug e.backtrace.join("\n")
|
81
|
+
end
|
82
|
+
now = Time.now
|
83
|
+
while @next_invocation_time <= now && @period > 0
|
84
|
+
@next_invocation_time += @period
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'new_relic/control'
|
2
|
+
|
3
|
+
module NewRelic
|
4
|
+
module CollectionHelper
|
5
|
+
DEFAULT_TRUNCATION_SIZE=16 * 1024
|
6
|
+
DEFAULT_ARRAY_TRUNCATION_SIZE=128
|
7
|
+
# Transform parameter hash into a hash whose values are strictly
|
8
|
+
# strings
|
9
|
+
def normalize_params(params)
|
10
|
+
case params
|
11
|
+
when Hash
|
12
|
+
# optimize for empty hash since that is often what this is called with.
|
13
|
+
return params if params.empty?
|
14
|
+
new_params = {}
|
15
|
+
params.each do | key, value |
|
16
|
+
new_params[truncate(normalize_params(key),64)] = normalize_params(value)
|
17
|
+
end
|
18
|
+
new_params
|
19
|
+
when Symbol, FalseClass, TrueClass, nil
|
20
|
+
params
|
21
|
+
when Numeric
|
22
|
+
truncate(params.to_s)
|
23
|
+
when String
|
24
|
+
truncate(params)
|
25
|
+
when Array
|
26
|
+
params.first(DEFAULT_ARRAY_TRUNCATION_SIZE).map{|item| normalize_params(item)}
|
27
|
+
else
|
28
|
+
truncate(flatten(params))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return an array of strings (backtrace), cleaned up for readability
|
33
|
+
# Return nil if there is no backtrace
|
34
|
+
|
35
|
+
def strip_nr_from_backtrace(backtrace)
|
36
|
+
if backtrace && !NewRelic::Control.instance.disable_backtrace_cleanup?
|
37
|
+
# this is for 1.9.1, where strings no longer have Enumerable
|
38
|
+
backtrace = backtrace.split("\n") if String === backtrace
|
39
|
+
backtrace = backtrace.map &:to_s
|
40
|
+
backtrace = backtrace.reject do |line|
|
41
|
+
line.include?(NewRelic::Control.newrelic_root) or
|
42
|
+
line =~ /^newrelic_rpm\s/
|
43
|
+
end
|
44
|
+
# rename methods back to their original state
|
45
|
+
backtrace = backtrace.collect {|line| line.gsub(/_without_(newrelic|trace)/, "")}
|
46
|
+
end
|
47
|
+
backtrace
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Convert any kind of object to a short string.
|
53
|
+
def flatten(object)
|
54
|
+
s = case object
|
55
|
+
when nil then ''
|
56
|
+
when object.instance_of?(String) then object
|
57
|
+
when String then String.new(object) # convert string subclasses to strings
|
58
|
+
else "#<#{object.class.to_s}>"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
def truncate(string, len=DEFAULT_TRUNCATION_SIZE)
|
62
|
+
case string
|
63
|
+
when Symbol then string
|
64
|
+
when nil then ""
|
65
|
+
when String
|
66
|
+
real_string = flatten(string)
|
67
|
+
if real_string.size > len
|
68
|
+
real_string = real_string.slice(0...len)
|
69
|
+
real_string << "..."
|
70
|
+
end
|
71
|
+
real_string
|
72
|
+
else
|
73
|
+
truncate(flatten(string), len)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
# Run the command given by the first argument. Right
|
4
|
+
# now all we have is deployments. We hope to have other
|
5
|
+
# kinds of events here later.
|
6
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/.."
|
7
|
+
module NewRelic
|
8
|
+
class Command
|
9
|
+
attr_accessor :leftover
|
10
|
+
# Capture a failure to execute the command.
|
11
|
+
class CommandFailure < StandardError
|
12
|
+
attr_reader :options
|
13
|
+
def initialize message, opt_parser=nil
|
14
|
+
super message
|
15
|
+
@options = opt_parser
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def info(message)
|
20
|
+
STDOUT.puts message
|
21
|
+
end
|
22
|
+
|
23
|
+
def err(message)
|
24
|
+
STDERR.puts message
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(command_line_args)
|
28
|
+
if Hash === command_line_args
|
29
|
+
# command line args is an options hash
|
30
|
+
command_line_args.each do | key, value |
|
31
|
+
instance_variable_set "@#{key}", value.to_s if value
|
32
|
+
end
|
33
|
+
else
|
34
|
+
# parse command line args. Throw an exception on a bad arg.
|
35
|
+
@options = options do | opts |
|
36
|
+
opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
|
37
|
+
end
|
38
|
+
@leftover = @options.parse(command_line_args)
|
39
|
+
end
|
40
|
+
rescue OptionParser::ParseError => e
|
41
|
+
raise CommandFailure.new(e.message, @options)
|
42
|
+
end
|
43
|
+
|
44
|
+
@commands = []
|
45
|
+
def self.inherited(subclass)
|
46
|
+
@commands << subclass
|
47
|
+
end
|
48
|
+
|
49
|
+
cmds = File.expand_path(File.join(File.dirname(__FILE__), 'commands', '*.rb'))
|
50
|
+
Dir[cmds].each{|command| require command }
|
51
|
+
|
52
|
+
def self.run
|
53
|
+
|
54
|
+
@command_names = @commands.map{ |c| c.command }
|
55
|
+
|
56
|
+
extra = []
|
57
|
+
options = ARGV.options do |opts|
|
58
|
+
script_name = File.basename($0)
|
59
|
+
if script_name =~ /newrelic_cmd$/
|
60
|
+
$stdout.puts "warning: the 'newrelic_cmd' script has been renamed 'newrelic'"
|
61
|
+
script_name = 'newrelic'
|
62
|
+
end
|
63
|
+
opts.banner = "Usage: #{script_name} [ #{ @command_names.join(" | ")} ] [options]"
|
64
|
+
opts.separator "use '#{script_name} <command> -h' to see detailed command options"
|
65
|
+
opts
|
66
|
+
end
|
67
|
+
extra = options.order!
|
68
|
+
command = extra.shift
|
69
|
+
# just make it a little easier on them
|
70
|
+
command = 'deployments' if command =~ /deploy/
|
71
|
+
if command.nil?
|
72
|
+
STDERR.puts options
|
73
|
+
elsif !@command_names.include?(command)
|
74
|
+
STDERR.puts "Unrecognized command: #{command}"
|
75
|
+
STDERR.puts options
|
76
|
+
else
|
77
|
+
command_class = @commands.find{ |c| c.command == command}
|
78
|
+
command_class.new(extra).run
|
79
|
+
end
|
80
|
+
rescue OptionParser::InvalidOption => e
|
81
|
+
raise NewRelic::Command::CommandFailure, e.message
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# This is a class for executing commands related to deployment
|
2
|
+
# events. It runs without loading the rails environment
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
require 'net/http'
|
6
|
+
require 'rexml/document'
|
7
|
+
|
8
|
+
# We need to use the Control object but we don't want to load
|
9
|
+
# the rails/merb environment. The defined? clause is so that
|
10
|
+
# it won't load it twice, something it does when run inside a test
|
11
|
+
require 'new_relic/control' unless defined? NewRelic::Control
|
12
|
+
|
13
|
+
class NewRelic::Command::Deployments < NewRelic::Command
|
14
|
+
attr_reader :config
|
15
|
+
def self.command; "deployments"; end
|
16
|
+
|
17
|
+
# Initialize the deployment uploader with command line args.
|
18
|
+
# Use -h to see options.
|
19
|
+
# When command_line_args is a hash, we are invoking directly and
|
20
|
+
# it's treated as an options with optional string values for
|
21
|
+
# :user, :description, :appname, :revision, :environment,
|
22
|
+
# and :changes.
|
23
|
+
#
|
24
|
+
# Will throw CommandFailed exception if there's any error.
|
25
|
+
#
|
26
|
+
def initialize command_line_args
|
27
|
+
@config = NewRelic::Control.instance
|
28
|
+
super(command_line_args)
|
29
|
+
@description ||= @leftover && @leftover.join(" ")
|
30
|
+
@user ||= ENV['USER']
|
31
|
+
config.env = @environment if @environment
|
32
|
+
@appname ||= config.app_names[0] || config.env || 'development'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Run the Deployment upload in New Relic via Active Resource.
|
36
|
+
# Will possibly print errors and exit the VM
|
37
|
+
def run
|
38
|
+
begin
|
39
|
+
@description = nil if @description && @description.strip.empty?
|
40
|
+
create_params = {}
|
41
|
+
{
|
42
|
+
:application_id => @appname,
|
43
|
+
:host => Socket.gethostname,
|
44
|
+
:description => @description,
|
45
|
+
:user => @user,
|
46
|
+
:revision => @revision,
|
47
|
+
:changelog => @changelog
|
48
|
+
}.each do |k, v|
|
49
|
+
create_params["deployment[#{k}]"] = v unless v.nil? || v == ''
|
50
|
+
end
|
51
|
+
http = config.http_connection(config.api_server)
|
52
|
+
|
53
|
+
uri = "/deployments.xml"
|
54
|
+
|
55
|
+
raise "license_key was not set in newrelic.yml for #{config.env}" if config['license_key'].nil?
|
56
|
+
request = Net::HTTP::Post.new(uri, {'x-license-key' => config['license_key']})
|
57
|
+
request.content_type = "application/octet-stream"
|
58
|
+
|
59
|
+
request.set_form_data(create_params)
|
60
|
+
|
61
|
+
response = http.request(request)
|
62
|
+
|
63
|
+
if response.is_a? Net::HTTPSuccess
|
64
|
+
info "Recorded deployment to '#{@appname}' (#{@description || Time.now })"
|
65
|
+
else
|
66
|
+
err_string = REXML::Document.new(response.body).elements['errors/error'].map(&:to_s).join("; ") rescue response.message
|
67
|
+
raise NewRelic::Command::CommandFailure, "Deployment not recorded: #{err_string}"
|
68
|
+
end
|
69
|
+
rescue SystemCallError, SocketError => e
|
70
|
+
# These include Errno connection errors
|
71
|
+
err_string = "Transient error attempting to connect to #{config.api_server} (#{e})"
|
72
|
+
raise NewRelic::Command::CommandFailure.new(err_string)
|
73
|
+
rescue NewRelic::Command::CommandFailure
|
74
|
+
raise
|
75
|
+
rescue => e
|
76
|
+
err "Unexpected error attempting to connect to #{config.api_server}"
|
77
|
+
info "#{e}: #{e.backtrace.join("\n ")}"
|
78
|
+
raise NewRelic::Command::CommandFailure.new(e.to_s)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def options
|
85
|
+
OptionParser.new %Q{Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] }, 40 do |o|
|
86
|
+
o.separator "OPTIONS:"
|
87
|
+
o.on("-a", "--appname=NAME", String,
|
88
|
+
"Set the application name.",
|
89
|
+
"Default is app_name setting in newrelic.yml") { | e | @appname = e }
|
90
|
+
o.on("-e", "--environment=name", String,
|
91
|
+
"Override the (RAILS|MERB|RUBY|RACK)_ENV setting",
|
92
|
+
"currently: #{config.env}") { | e | @environment = e }
|
93
|
+
o.on("-u", "--user=USER", String,
|
94
|
+
"Specify the user deploying, for information only",
|
95
|
+
"Default: #{@user || '<none>'}") { | u | @user = u }
|
96
|
+
o.on("-r", "--revision=REV", String,
|
97
|
+
"Specify the revision being deployed") { | r | @revision = r }
|
98
|
+
o.on("-c", "--changes",
|
99
|
+
"Read in a change log from the standard input") { @changelog = STDIN.read }
|
100
|
+
yield o if block_given?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'new_relic/version'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
class NewRelic::Command::Install < NewRelic::Command
|
6
|
+
|
7
|
+
NO_LICENSE_KEY = "<PASTE LICENSE KEY HERE>"
|
8
|
+
|
9
|
+
def self.command; "install"; end
|
10
|
+
|
11
|
+
# Use -h to see options.
|
12
|
+
# When command_line_args is a hash, we are invoking directly and
|
13
|
+
# it's treated as an options with optional string values for
|
14
|
+
# :user, :description, :appname, :revision, :environment,
|
15
|
+
# and :changes.
|
16
|
+
#
|
17
|
+
# Will throw CommandFailed exception if there's any error.
|
18
|
+
#
|
19
|
+
attr_reader :dest_dir, :license_key, :generated_for_user, :quiet, :src_file, :app_name
|
20
|
+
def initialize command_line_args={}
|
21
|
+
super command_line_args
|
22
|
+
if !@dest_dir
|
23
|
+
# Install a newrelic.yml file into the local config directory.
|
24
|
+
if File.directory? "config"
|
25
|
+
@dest_dir = "config"
|
26
|
+
else
|
27
|
+
@dest_dir = "."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@license_key ||= NO_LICENSE_KEY
|
31
|
+
@app_name ||= @leftover
|
32
|
+
raise CommandFailure.new("Application name required.", @options) unless @app_name && @app_name.size > 0
|
33
|
+
@generated_for_user ||= @user_string || ""
|
34
|
+
end
|
35
|
+
|
36
|
+
def run
|
37
|
+
dest_file = File.expand_path(@dest_dir + "/newrelic.yml")
|
38
|
+
if File.exist?(dest_file)
|
39
|
+
raise NewRelic::Command::CommandFailure, "newrelic.yml file already exists. Move it out of the way."
|
40
|
+
end
|
41
|
+
File.open(dest_file, 'w') { | out | out.puts(content) }
|
42
|
+
|
43
|
+
puts <<-EOF unless quiet
|
44
|
+
|
45
|
+
Installed a default configuration file at
|
46
|
+
#{dest_file}.
|
47
|
+
EOF
|
48
|
+
puts <<-EOF unless quiet || @license_key != NO_LICENSE_KEY
|
49
|
+
|
50
|
+
To monitor your application in production mode, sign up for an account
|
51
|
+
at www.newrelic.com, and replace the newrelic.yml file with the one
|
52
|
+
you receive upon registration.
|
53
|
+
EOF
|
54
|
+
puts <<-EOF unless quiet
|
55
|
+
|
56
|
+
E-mail support@newrelic.com with any problems or questions.
|
57
|
+
EOF
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def content
|
62
|
+
@src_file ||= File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","newrelic.yml"))
|
63
|
+
template = File.read(@src_file)
|
64
|
+
ERB.new(template).result(binding)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def options
|
70
|
+
OptionParser.new "Usage: #{$0} #{self.class.command} [ OPTIONS] 'application name'", 40 do |o|
|
71
|
+
o.on("-l", "--license_key=NAME", String,
|
72
|
+
"Use the given license key") { | e | @license_key = e }
|
73
|
+
o.on("-d", "--destdir=name", String,
|
74
|
+
"Write the newrelic.yml to the given directory, default is '.'") { | e | @dest_dir = e }
|
75
|
+
yield o if block_given?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'conditional_vendored_metric_parser'
|
3
|
+
require 'conditional_vendored_dependency_detection'
|
4
|
+
require 'new_relic/local_environment'
|
5
|
+
|
6
|
+
require 'singleton'
|
7
|
+
require 'erb'
|
8
|
+
require 'socket'
|
9
|
+
require 'net/https'
|
10
|
+
require 'logger'
|
11
|
+
require 'new_relic/control/frameworks'
|
12
|
+
require 'new_relic/control/profiling'
|
13
|
+
require 'new_relic/control/logging_methods'
|
14
|
+
require 'new_relic/control/configuration'
|
15
|
+
require 'new_relic/control/server_methods'
|
16
|
+
require 'new_relic/control/instrumentation'
|
17
|
+
require 'new_relic/control/class_methods'
|
18
|
+
require 'new_relic/control/instance_methods'
|
19
|
+
|
20
|
+
require 'new_relic/agent'
|
21
|
+
require 'new_relic/delayed_job_injection'
|
22
|
+
|
23
|
+
|
24
|
+
module NewRelic
|
25
|
+
|
26
|
+
# The Control is a singleton responsible for the startup and
|
27
|
+
# initialization sequence. The initializer uses a LocalEnvironment to
|
28
|
+
# detect the framework and instantiates the framework specific
|
29
|
+
# subclass.
|
30
|
+
#
|
31
|
+
# The Control also implements some of the public API for the agent.
|
32
|
+
#
|
33
|
+
class Control
|
34
|
+
# done in a subfile for load order purposes
|
35
|
+
# extend ClassMethods
|
36
|
+
# include InstanceMethods
|
37
|
+
# include Profiling
|
38
|
+
# include LoggingMethods
|
39
|
+
# include Configuration
|
40
|
+
# include ServerMethods
|
41
|
+
# include Instrumentation
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|