ghazel-newrelic_rpm 3.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +525 -0
- data/LICENSE +37 -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 +423 -0
- data/lib/new_relic/agent/agent.rb +1040 -0
- data/lib/new_relic/agent/beacon_configuration.rb +61 -0
- data/lib/new_relic/agent/browser_monitoring.rb +83 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +203 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +21 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +62 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +13 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +413 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +232 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +44 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +56 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +36 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +23 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +326 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +84 -0
- data/lib/new_relic/agent/instrumentation/net.rb +23 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +34 -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 +83 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +36 -0
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +108 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +36 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +60 -0
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +112 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +31 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +54 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +23 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +16 -0
- data/lib/new_relic/agent/method_tracer.rb +422 -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 +144 -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/stats_engine.rb +24 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +182 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +89 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +184 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
- data/lib/new_relic/agent/transaction_sampler.rb +378 -0
- data/lib/new_relic/agent/worker_loop.rb +81 -0
- data/lib/new_relic/collection_helper.rb +69 -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 +91 -0
- data/lib/new_relic/control.rb +48 -0
- data/lib/new_relic/control/class_methods.rb +47 -0
- data/lib/new_relic/control/configuration.rb +157 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +30 -0
- data/lib/new_relic/control/frameworks/rails.rb +151 -0
- data/lib/new_relic/control/frameworks/rails3.rb +70 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +23 -0
- data/lib/new_relic/control/instance_methods.rb +154 -0
- data/lib/new_relic/control/instrumentation.rb +81 -0
- data/lib/new_relic/control/logging_methods.rb +88 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +104 -0
- data/lib/new_relic/data_serialization.rb +84 -0
- data/lib/new_relic/delayed_job_injection.rb +38 -0
- data/lib/new_relic/histogram.rb +91 -0
- data/lib/new_relic/local_environment.rb +391 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +46 -0
- data/lib/new_relic/metric_spec.rb +73 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/browser_monitoring.rb +68 -0
- data/lib/new_relic/rack/developer_mode.rb +267 -0
- data/lib/new_relic/rack/metric_app.rb +65 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +28 -0
- data/lib/new_relic/rack/newrelic.yml +27 -0
- data/lib/new_relic/rack_app.rb +6 -0
- data/lib/new_relic/recipes.rb +73 -0
- data/lib/new_relic/stats.rb +378 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +76 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -0
- data/lib/new_relic/transaction_sample.rb +272 -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 +251 -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 +330 -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/new_relic/agent/agent/connect_test.rb +316 -0
- data/test/new_relic/agent/agent/start_test.rb +340 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +155 -0
- data/test/new_relic/agent/agent_test.rb +173 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +366 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +104 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +274 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +168 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +522 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +179 -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 +387 -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 +107 -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/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +81 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +185 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +945 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/collection_helper_test.rb +127 -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/logging_methods_test.rb +157 -0
- data/test/new_relic/control_test.rb +195 -0
- data/test/new_relic/data_serialization_test.rb +70 -0
- data/test/new_relic/local_environment_test.rb +72 -0
- data/test/new_relic/metric_data_test.rb +125 -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 +84 -0
- data/test/new_relic/rack/developer_mode_test.rb +43 -0
- data/test/new_relic/stats_test.rb +426 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -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 +454 -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 +170 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +144 -0
- data/ui/helpers/developer_mode_helper.rb +351 -0
- data/ui/helpers/google_pie_chart.rb +49 -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 +19 -0
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -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/LICENSE +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -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 +122 -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 +66 -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 +399 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module NewRelic
|
3
|
+
class DataSerialization
|
4
|
+
module ClassMethods
|
5
|
+
def should_send_data?
|
6
|
+
NewRelic::Control.instance.disable_serialization? || (File.size(file_path) >= max_size)
|
7
|
+
rescue Exception => e
|
8
|
+
# This is not what we really should do here, but the fail-safe
|
9
|
+
# behavior is to do what the older agent did: send data every
|
10
|
+
# time we think we might want to send data.
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_and_write_to_file
|
15
|
+
with_locked_store do |f|
|
16
|
+
result = (yield get_data_from_file(f))
|
17
|
+
f.rewind
|
18
|
+
f.write(dump(result)) if result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def open_arguments
|
25
|
+
if defined?(Encoding)
|
26
|
+
[file_path, File::RDWR | File::CREAT, {:internal_encoding => nil}]
|
27
|
+
else
|
28
|
+
[file_path, File::RDWR | File::CREAT]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_locked_store
|
33
|
+
File.open(*open_arguments) do |f|
|
34
|
+
f.flock(File::LOCK_EX)
|
35
|
+
begin
|
36
|
+
yield(f)
|
37
|
+
ensure
|
38
|
+
f.flock(File::LOCK_UN)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
rescue Exception => e
|
42
|
+
NewRelic::Control.instance.log.error("Error serializing data to disk: #{e.inspect}")
|
43
|
+
NewRelic::Control.instance.log.debug(e.backtrace.split("\n"))
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_data_from_file(f)
|
47
|
+
data = f.read
|
48
|
+
result = load(data)
|
49
|
+
f.truncate(0)
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
def max_size
|
54
|
+
10_000
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_file_if_needed
|
58
|
+
FileUtils.touch(file_path) unless File.exists?(file_path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def dump(object)
|
62
|
+
Marshal.dump(object)
|
63
|
+
end
|
64
|
+
|
65
|
+
def load(dump)
|
66
|
+
Marshal.load(dump)
|
67
|
+
rescue ArgumentError => e
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def truncate_file
|
72
|
+
create_file_if_needed
|
73
|
+
File.truncate(file_path, 0)
|
74
|
+
end
|
75
|
+
|
76
|
+
def file_path
|
77
|
+
# TODO get configuration from main control
|
78
|
+
'./log/newrelic_agent_store.db'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
extend ClassMethods
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'dependency_detection'
|
2
|
+
# This installs some code to manually start the agent when a delayed
|
3
|
+
# job worker starts. It's not really instrumentation. It's more like
|
4
|
+
# a hook from DJ to the Ruby Agent so it gets loaded at the time the
|
5
|
+
# Ruby Agent initializes, which must be before the DJ worker
|
6
|
+
# initializes. Loaded from control.rb
|
7
|
+
module NewRelic
|
8
|
+
module DelayedJobInjection
|
9
|
+
extend self
|
10
|
+
attr_accessor :worker_name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
DependencyDetection.defer do
|
15
|
+
depends_on do
|
16
|
+
defined?(::Delayed) && defined?(::Delayed::Worker)
|
17
|
+
end
|
18
|
+
|
19
|
+
executes do
|
20
|
+
Delayed::Worker.class_eval do
|
21
|
+
def initialize_with_new_relic(*args)
|
22
|
+
initialize_without_new_relic(*args)
|
23
|
+
worker_name = case
|
24
|
+
when self.respond_to?(:name) then self.name
|
25
|
+
when self.class.respond_to?(:default_name) then self.class.default_name
|
26
|
+
end
|
27
|
+
dispatcher_instance_id = worker_name || "host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
|
28
|
+
say "New Relic Ruby Agent Monitoring DJ worker #{dispatcher_instance_id}"
|
29
|
+
NewRelic::DelayedJobInjection.worker_name = worker_name
|
30
|
+
NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job, :dispatcher_instance_id => dispatcher_instance_id
|
31
|
+
end
|
32
|
+
|
33
|
+
alias initialize_without_new_relic initialize
|
34
|
+
alias initialize initialize_with_new_relic
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
DependencyDetection.detect!
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Histogram is used for organizing response times
|
2
|
+
# into an 'Exponential Histogram'. Feature based in part on DHH proposal:
|
3
|
+
# http://37signals.com/svn/posts/1836-the-problem-with-averages
|
4
|
+
#
|
5
|
+
# Histogram builds a set of buckets of geometrically growing size, with the assumption that most
|
6
|
+
# apps have long-tail response times, and therefore you need the most granularity at the lowest
|
7
|
+
# r/t level.
|
8
|
+
module NewRelic
|
9
|
+
class Histogram
|
10
|
+
|
11
|
+
# Used to stub out API methods when the agent is not enabled
|
12
|
+
module Shim
|
13
|
+
def process(response_time); end
|
14
|
+
end
|
15
|
+
# Stores statistics for response times falling in a particular range.
|
16
|
+
# A bucket has a min and max response time. A response time event
|
17
|
+
# falls in a bucket if min <= r/t < max. A bucket also
|
18
|
+
# has an associated metric for reporting data to New Relic. The
|
19
|
+
# bucket range is encoded in the metic name
|
20
|
+
class Bucket
|
21
|
+
|
22
|
+
attr_reader :min, :max, :stats
|
23
|
+
|
24
|
+
def initialize(min, max = nil)
|
25
|
+
@min = min
|
26
|
+
@max = max
|
27
|
+
end
|
28
|
+
|
29
|
+
def stats
|
30
|
+
NewRelic::Agent.get_stats("Response Times/#{min_millis}/#{max_millis}")
|
31
|
+
end
|
32
|
+
|
33
|
+
# This has return value like <=> but does something more
|
34
|
+
# than simply compare. If the value falls within range for
|
35
|
+
# the bucket, increment count and return 0; otherwise return
|
36
|
+
# a value < 0 if the value belongs in a bucket with a lower range
|
37
|
+
# you can guess what it returns if the value belongs in a bucket
|
38
|
+
# with a higher range. (Hint: it's not 0, and it's not less than zero.)
|
39
|
+
def process(value)
|
40
|
+
if value < min
|
41
|
+
return -1
|
42
|
+
|
43
|
+
# max == nil means unlimited max (last bucket)
|
44
|
+
elsif max && value >= max
|
45
|
+
return 1
|
46
|
+
|
47
|
+
else
|
48
|
+
stats.record_data_point(value)
|
49
|
+
return 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def min_millis
|
54
|
+
(min * 1000).round
|
55
|
+
end
|
56
|
+
|
57
|
+
def max_millis
|
58
|
+
max.nil? ? nil : (max * 1000).round
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"#{min_millis} - #{max_millis}: #{stats.call_count}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
attr_reader :buckets
|
67
|
+
|
68
|
+
# Histogram uses apdex T / 10 as its minimum bucket size, and grows from there.
|
69
|
+
# 30 data points should be adequate resolution.
|
70
|
+
def initialize(first_bucket_max = 0.010, bucket_count = 30, multiplier = 1.3)
|
71
|
+
@buckets = []
|
72
|
+
|
73
|
+
min = 0
|
74
|
+
max = first_bucket_max
|
75
|
+
|
76
|
+
(bucket_count - 1).times do
|
77
|
+
@buckets << Bucket.new(min, max)
|
78
|
+
min = max
|
79
|
+
max *= multiplier
|
80
|
+
end
|
81
|
+
@buckets << Bucket.new(max)
|
82
|
+
end
|
83
|
+
|
84
|
+
def process(response_time)
|
85
|
+
buckets.each do |bucket|
|
86
|
+
found = bucket.process(response_time)
|
87
|
+
return if found == 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,391 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'new_relic/version'
|
3
|
+
|
4
|
+
module NewRelic
|
5
|
+
# An instance of LocalEnvironment is responsible for determining
|
6
|
+
# three things:
|
7
|
+
#
|
8
|
+
# * Framework - :rails, :rails3, :merb, :ruby, :external, :test
|
9
|
+
# * Dispatcher - A supported dispatcher, or nil (:mongrel, :thin, :passenger, :webrick, etc)
|
10
|
+
# * Dispatcher Instance ID, which distinguishes agents on a single host from each other
|
11
|
+
#
|
12
|
+
# If the environment can't be determined, it will be set to
|
13
|
+
# nil and dispatcher_instance_id will have nil.
|
14
|
+
#
|
15
|
+
# NewRelic::LocalEnvironment should be accessed through NewRelic::Control#env (via the NewRelic::Control singleton).
|
16
|
+
class LocalEnvironment
|
17
|
+
|
18
|
+
attr_accessor :dispatcher # mongrel, thin, webrick, or possibly nil
|
19
|
+
attr_accessor :dispatcher_instance_id # used to distinguish instances of a dispatcher from each other, may be nil
|
20
|
+
attr_accessor :framework # rails, rails3, merb, external, ruby, test
|
21
|
+
attr_reader :mongrel # The mongrel instance, if there is one, captured as a convenience
|
22
|
+
attr_reader :processors # The number of cpus, if detected, or nil
|
23
|
+
alias environment dispatcher
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
# Extend self with any any submodules of LocalEnvironment. These can override
|
27
|
+
# the discover methods to discover new framworks and dispatchers.
|
28
|
+
NewRelic::LocalEnvironment.constants.each do | const |
|
29
|
+
mod = NewRelic::LocalEnvironment.const_get const
|
30
|
+
self.extend mod if mod.instance_of? Module
|
31
|
+
end
|
32
|
+
|
33
|
+
discover_framework
|
34
|
+
discover_dispatcher
|
35
|
+
@dispatcher = nil if @dispatcher == :none
|
36
|
+
@gems = Set.new
|
37
|
+
@plugins = Set.new
|
38
|
+
@config = Hash.new
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add the given key/value pair to the app environment
|
42
|
+
# settings. Must pass either a value or a block. Block
|
43
|
+
# is called to get the value and any raised errors are
|
44
|
+
# silently ignored.
|
45
|
+
def append_environment_value(name, value = nil)
|
46
|
+
value = yield if block_given?
|
47
|
+
@config[name] = value if value
|
48
|
+
rescue Exception
|
49
|
+
# puts "#{e}\n #{e.backtrace.join("\n ")}"
|
50
|
+
raise if @framework == :test
|
51
|
+
end
|
52
|
+
|
53
|
+
def append_gem_list
|
54
|
+
@gems += yield
|
55
|
+
rescue Exception => e
|
56
|
+
# puts "#{e}\n #{e.backtrace.join("\n ")}"
|
57
|
+
raise if @framework == :test
|
58
|
+
end
|
59
|
+
|
60
|
+
def append_plugin_list
|
61
|
+
@plugins += yield
|
62
|
+
rescue Exception
|
63
|
+
# puts "#{e}\n #{e.backtrace.join("\n ")}"
|
64
|
+
raise if @framework == :test
|
65
|
+
end
|
66
|
+
|
67
|
+
def dispatcher_instance_id
|
68
|
+
if @dispatcher_instance_id.nil?
|
69
|
+
if @dispatcher.nil?
|
70
|
+
@dispatcher_instance_id = File.basename($0).split(".").first
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@dispatcher_instance_id
|
74
|
+
end
|
75
|
+
|
76
|
+
def gather_ruby_info
|
77
|
+
append_environment_value('Ruby version'){ RUBY_VERSION }
|
78
|
+
append_environment_value('Ruby description'){ RUBY_DESCRIPTION } if defined? ::RUBY_DESCRIPTION
|
79
|
+
append_environment_value('Ruby platform') { RUBY_PLATFORM }
|
80
|
+
append_environment_value('Ruby patchlevel') { RUBY_PATCHLEVEL }
|
81
|
+
# room here for other ruby implementations, when.
|
82
|
+
if defined? ::JRUBY_VERSION
|
83
|
+
gather_jruby_info
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def gather_jruby_info
|
88
|
+
append_environment_value('JRuby version') { JRUBY_VERSION }
|
89
|
+
append_environment_value('Java VM version') { ENV_JAVA['java.vm.version']}
|
90
|
+
end
|
91
|
+
|
92
|
+
# See what the number of cpus is, works only on linux.
|
93
|
+
def gather_cpu_info
|
94
|
+
return unless File.readable? '/proc/cpuinfo'
|
95
|
+
@processors = append_environment_value('Processors') do
|
96
|
+
processors = File.readlines('/proc/cpuinfo').select { |line| line =~ /^processor\s*:/ }.size
|
97
|
+
raise "Cannot determine the number of processors in /proc/cpuinfo" unless processors > 0
|
98
|
+
processors
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def gather_architecture_info
|
103
|
+
append_environment_value('Arch') { `uname -p` } ||
|
104
|
+
append_environment_value('Arch') { ENV['PROCESSOR_ARCHITECTURE'] }
|
105
|
+
end
|
106
|
+
|
107
|
+
def gather_os_info
|
108
|
+
append_environment_value('OS version') { `uname -v` }
|
109
|
+
append_environment_value('OS') { `uname -s` } ||
|
110
|
+
append_environment_value('OS') { ENV['OS'] }
|
111
|
+
end
|
112
|
+
|
113
|
+
def gather_system_info
|
114
|
+
gather_architecture_info
|
115
|
+
gather_cpu_info
|
116
|
+
end
|
117
|
+
|
118
|
+
def gather_revision_info
|
119
|
+
# Look for a capistrano file indicating the current revision:
|
120
|
+
rev_file = File.join(NewRelic::Control.instance.root, "REVISION")
|
121
|
+
if File.readable?(rev_file) && File.size(rev_file) < 64
|
122
|
+
append_environment_value('Revision') do
|
123
|
+
File.open(rev_file) { | file | file.readline.strip }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def gather_ar_adapter_info
|
129
|
+
# The name of the database adapter for the current environment.
|
130
|
+
append_environment_value 'Database adapter' do
|
131
|
+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
|
132
|
+
ActiveRecord::Base.respond_to?(:configurations)
|
133
|
+
config = ActiveRecord::Base.configurations[NewRelic::Control.instance.env]
|
134
|
+
if config
|
135
|
+
config['adapter']
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
append_environment_value 'Database schema version' do
|
140
|
+
ActiveRecord::Migrator.current_version
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def gather_dm_adapter_info
|
145
|
+
append_environment_value 'DataMapper version' do
|
146
|
+
require 'dm-core/version'
|
147
|
+
DataMapper::VERSION
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def gather_db_info
|
152
|
+
# room here for more database adapters, when.
|
153
|
+
if defined? ::ActiveRecord
|
154
|
+
gather_ar_adapter_info
|
155
|
+
end
|
156
|
+
if defined? ::DataMapper
|
157
|
+
gather_dm_adapter_info
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Collect base statistics about the environment and record them for
|
162
|
+
# comparison and change detection.
|
163
|
+
def gather_environment_info
|
164
|
+
append_environment_value 'Framework', @framework.to_s
|
165
|
+
append_environment_value 'Dispatcher', @dispatcher.to_s if @dispatcher
|
166
|
+
append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
|
167
|
+
append_environment_value('Environment') { NewRelic::Control.instance.env }
|
168
|
+
|
169
|
+
# miscellaneous other helpful debugging information
|
170
|
+
gather_ruby_info
|
171
|
+
gather_system_info
|
172
|
+
gather_revision_info
|
173
|
+
gather_db_info
|
174
|
+
end
|
175
|
+
|
176
|
+
# Take a snapshot of the environment information for this application
|
177
|
+
# Returns an associative array
|
178
|
+
def snapshot
|
179
|
+
i = @config.to_a
|
180
|
+
i << [ 'Plugin List', @plugins.to_a] if not @plugins.empty?
|
181
|
+
i << [ 'Gems', @gems.to_a] if not @gems.empty?
|
182
|
+
i
|
183
|
+
end
|
184
|
+
|
185
|
+
def working_jruby?
|
186
|
+
!(defined?(::JRuby) && JRuby.respond_to?(:runtime) && !JRuby.runtime.is_object_space_enabled)
|
187
|
+
end
|
188
|
+
|
189
|
+
def find_class_in_object_space(klass)
|
190
|
+
ObjectSpace.each_object(klass) do |x|
|
191
|
+
return x
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def mongrel
|
196
|
+
return @mongrel if @mongrel
|
197
|
+
if defined?(::Mongrel) && defined?(::Mongrel::HttpServer) && working_jruby?
|
198
|
+
@mongrel = find_class_in_object_space(::Mongrel::HttpServer)
|
199
|
+
end
|
200
|
+
@mongrel
|
201
|
+
end
|
202
|
+
|
203
|
+
def unicorn
|
204
|
+
return @unicorn if @unicorn
|
205
|
+
if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && working_jruby?
|
206
|
+
@unicorn = find_class_in_object_space(::Unicorn::HttpServer)
|
207
|
+
end
|
208
|
+
@unicorn
|
209
|
+
end
|
210
|
+
|
211
|
+
private
|
212
|
+
|
213
|
+
# Although you can override the framework with NEWRELIC_DISPATCHER this
|
214
|
+
# is not advisable since it implies certain api's being available.
|
215
|
+
def discover_dispatcher
|
216
|
+
@dispatcher ||= ENV['NEWRELIC_DISPATCHER'] && ENV['NEWRELIC_DISPATCHER'].to_sym
|
217
|
+
dispatchers = %w[passenger torquebox glassfish thin mongrel litespeed webrick fastcgi unicorn sinatra]
|
218
|
+
while dispatchers.any? && @dispatcher.nil?
|
219
|
+
send 'check_for_'+(dispatchers.shift)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def discover_framework
|
224
|
+
# Although you can override the framework with NEWRELIC_FRAMEWORK this
|
225
|
+
# is not advisable since it implies certain api's being available.
|
226
|
+
#
|
227
|
+
# Note that the odd defined? sequence is necessary to work around a bug in an older version
|
228
|
+
# of JRuby.
|
229
|
+
@framework ||= case
|
230
|
+
when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
|
231
|
+
when defined?(::NewRelic::TEST) then :test
|
232
|
+
when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
|
233
|
+
when defined?(::Rails) then check_rails_version
|
234
|
+
when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
|
235
|
+
when defined?(::NewRelic::IA) then :external
|
236
|
+
else :ruby
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def check_rails_version
|
241
|
+
if Rails::VERSION::MAJOR < 3
|
242
|
+
:rails
|
243
|
+
else
|
244
|
+
:rails3
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def check_for_torquebox
|
249
|
+
return unless defined?(::JRuby) &&
|
250
|
+
( org.torquebox::TorqueBox rescue nil)
|
251
|
+
@dispatcher = :torquebox
|
252
|
+
end
|
253
|
+
|
254
|
+
def check_for_glassfish
|
255
|
+
return unless defined?(::JRuby) &&
|
256
|
+
(((com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
|
257
|
+
defined?(com::sun::grizzly::jruby::rack::DefaultRackApplicationFactory)) ||
|
258
|
+
(jruby_rack? && defined?(::GlassFish::Server)))
|
259
|
+
@dispatcher = :glassfish
|
260
|
+
end
|
261
|
+
|
262
|
+
def check_for_trinidad
|
263
|
+
return unless defined?(::JRuby) && jruby_rack? && defined?(::Trinidad::Server)
|
264
|
+
@dispatcher = :trinidad
|
265
|
+
end
|
266
|
+
|
267
|
+
def jruby_rack?
|
268
|
+
((org.jruby.rack.DefaultRackApplicationFactory rescue nil) &&
|
269
|
+
defined?(org::jruby::rack::DefaultRackApplicationFactory))
|
270
|
+
end
|
271
|
+
|
272
|
+
def check_for_webrick
|
273
|
+
return unless defined?(::WEBrick) && defined?(::WEBrick::VERSION)
|
274
|
+
@dispatcher = :webrick
|
275
|
+
if defined?(::OPTIONS) && OPTIONS.respond_to?(:fetch)
|
276
|
+
# OPTIONS is set by script/server
|
277
|
+
@dispatcher_instance_id = OPTIONS.fetch(:port)
|
278
|
+
end
|
279
|
+
@dispatcher_instance_id = default_port unless @dispatcher_instance_id
|
280
|
+
end
|
281
|
+
|
282
|
+
def check_for_fastcgi
|
283
|
+
return unless defined?(::FCGI)
|
284
|
+
@dispatcher = :fastcgi
|
285
|
+
end
|
286
|
+
|
287
|
+
# this case covers starting by mongrel_rails
|
288
|
+
def check_for_mongrel
|
289
|
+
return unless defined?(::Mongrel) && defined?(::Mongrel::HttpServer)
|
290
|
+
@dispatcher = :mongrel
|
291
|
+
|
292
|
+
# Get the port from the server if it's started
|
293
|
+
|
294
|
+
if mongrel && mongrel.respond_to?(:port)
|
295
|
+
@dispatcher_instance_id = mongrel.port.to_s
|
296
|
+
end
|
297
|
+
|
298
|
+
# Get the port from the configurator if one was created
|
299
|
+
if @dispatcher_instance_id.nil? && defined?(::Mongrel::Configurator)
|
300
|
+
ObjectSpace.each_object(Mongrel::Configurator) do |mongrel|
|
301
|
+
@dispatcher_instance_id = mongrel.defaults[:port] && mongrel.defaults[:port].to_s
|
302
|
+
end unless defined?(::JRuby) && !JRuby.runtime.is_object_space_enabled
|
303
|
+
end
|
304
|
+
|
305
|
+
# Still can't find the port. Let's look at ARGV to fall back
|
306
|
+
@dispatcher_instance_id = default_port if @dispatcher_instance_id.nil?
|
307
|
+
end
|
308
|
+
|
309
|
+
def check_for_unicorn
|
310
|
+
return unless defined?(::Unicorn) && defined?(::Unicorn::HttpServer)
|
311
|
+
|
312
|
+
# unlike mongrel, unicorn manages muliple threads and ports, so we
|
313
|
+
# have to map multiple processes into one instance, as we do with passenger
|
314
|
+
@dispatcher = :unicorn
|
315
|
+
end
|
316
|
+
|
317
|
+
def check_for_sinatra
|
318
|
+
return unless defined?(::Sinatra) && defined?(::Sinatra::Base)
|
319
|
+
|
320
|
+
begin
|
321
|
+
version = ::Sinatra::VERSION
|
322
|
+
rescue
|
323
|
+
$stderr.puts("Error determining Sinatra version")
|
324
|
+
end
|
325
|
+
|
326
|
+
if ::NewRelic::VersionNumber.new('0.9.2') > version
|
327
|
+
$stderr.puts("Your Sinatra version is #{version}, we highly recommend upgrading to >=0.9.2")
|
328
|
+
end
|
329
|
+
|
330
|
+
@dispatcher = :sinatra
|
331
|
+
end
|
332
|
+
|
333
|
+
def check_for_thin
|
334
|
+
if defined?(::Thin) && defined?(::Thin::Server)
|
335
|
+
# This case covers the thin web dispatcher
|
336
|
+
# Same issue as above- we assume only one instance per process
|
337
|
+
ObjectSpace.each_object(Thin::Server) do |thin_dispatcher|
|
338
|
+
@dispatcher = :thin
|
339
|
+
backend = thin_dispatcher.backend
|
340
|
+
# We need a way to uniquely identify and distinguish agents. The port
|
341
|
+
# works for this. When using sockets, use the socket file name.
|
342
|
+
if backend.respond_to? :port
|
343
|
+
@dispatcher_instance_id = backend.port
|
344
|
+
elsif backend.respond_to? :socket
|
345
|
+
@dispatcher_instance_id = backend.socket
|
346
|
+
else
|
347
|
+
raise "Unknown thin backend: #{backend}"
|
348
|
+
end
|
349
|
+
end # each thin instance
|
350
|
+
end
|
351
|
+
if defined?(::Thin) && defined?(::Thin::VERSION) && !@dispatcher
|
352
|
+
@dispatcher = :thin
|
353
|
+
@dispatcher_instance_id = default_port
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def check_for_litespeed
|
358
|
+
if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/
|
359
|
+
@dispatcher = :litespeed
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def check_for_passenger
|
364
|
+
if (defined?(::Passenger) && defined?(::Passenger::AbstractServer)) || defined?(::IN_PHUSION_PASSENGER)
|
365
|
+
@dispatcher = :passenger
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
def default_port
|
371
|
+
require 'optparse'
|
372
|
+
# If nothing else is found, use the 3000 default
|
373
|
+
default_port = 3000
|
374
|
+
OptionParser.new do |opts|
|
375
|
+
opts.on("-p", "--port=port", String) { | p | default_port = p }
|
376
|
+
opts.parse(ARGV.clone) rescue nil
|
377
|
+
end
|
378
|
+
default_port
|
379
|
+
end
|
380
|
+
|
381
|
+
public
|
382
|
+
def to_s
|
383
|
+
s = "LocalEnvironment["
|
384
|
+
s << @framework.to_s
|
385
|
+
s << ";dispatcher=#{@dispatcher}" if @dispatcher
|
386
|
+
s << ";instance=#{@dispatcher_instance_id}" if @dispatcher_instance_id
|
387
|
+
s << "]"
|
388
|
+
end
|
389
|
+
|
390
|
+
end
|
391
|
+
end
|