newrelic_rpm 2.8.11 → 2.9.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +267 -0
- data/LICENSE +1 -1
- data/Manifest +142 -0
- data/README.md +138 -0
- data/Rakefile +10 -28
- data/bin/mongrel_rpm +33 -0
- data/cert/cacert.pem +34 -0
- data/init.rb +38 -0
- data/lib/new_relic/agent/agent.rb +160 -347
- data/lib/new_relic/agent/collection_helper.rb +13 -24
- data/lib/new_relic/agent/error_collector.rb +29 -15
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
- data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +159 -135
- data/lib/new_relic/agent/patch_const_missing.rb +46 -26
- data/lib/new_relic/agent/sampler.rb +12 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
- data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
- data/lib/new_relic/agent/shim_agent.rb +11 -0
- data/lib/new_relic/agent/stats_engine.rb +85 -46
- data/lib/new_relic/agent/transaction_sampler.rb +63 -38
- data/lib/new_relic/agent/worker_loop.rb +8 -18
- data/lib/new_relic/agent.rb +200 -25
- data/lib/new_relic/commands/deployments.rb +9 -9
- data/lib/new_relic/control/merb.rb +22 -0
- data/lib/new_relic/control/rails.rb +141 -0
- data/lib/new_relic/{config → control}/ruby.rb +13 -2
- data/lib/new_relic/control.rb +424 -0
- data/lib/new_relic/local_environment.rb +201 -79
- data/lib/new_relic/metric_data.rb +7 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +11 -0
- data/lib/new_relic/metric_parser/controller.rb +51 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/database.rb +23 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_parser.rb +107 -0
- data/lib/new_relic/metric_spec.rb +5 -0
- data/lib/new_relic/noticed_error.rb +5 -1
- data/lib/new_relic/rack/metric_app.rb +57 -0
- data/lib/new_relic/rack/newrelic.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +25 -0
- data/lib/new_relic/rack.rb +5 -0
- data/lib/new_relic/recipes.rb +10 -3
- data/lib/new_relic/stats.rb +130 -144
- data/lib/new_relic/transaction_analysis.rb +7 -8
- data/lib/new_relic/transaction_sample.rb +86 -10
- data/lib/new_relic/version.rb +41 -160
- data/lib/new_relic_api.rb +7 -6
- data/lib/newrelic_rpm.rb +30 -17
- data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
- data/newrelic.yml +115 -62
- data/newrelic_rpm.gemspec +36 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +21 -3
- data/test/config/{test_config.rb → test_control.rb} +14 -10
- data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
- data/test/new_relic/agent/agent_test.rb +104 -0
- data/test/new_relic/agent/agent_test_controller.rb +18 -1
- data/test/new_relic/agent/classloader_patch_test.rb +56 -0
- data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
- data/test/new_relic/agent/controller_test.rb +107 -0
- data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
- data/test/new_relic/agent/error_collector_test.rb +155 -0
- data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/stats_engine_test.rb +266 -0
- data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
- data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
- data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
- data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
- data/test/new_relic/control_test.rb +97 -0
- data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +142 -0
- data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
- data/test/new_relic/samplers_test.rb +71 -0
- data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
- data/test/new_relic/stats_test.rb +291 -0
- data/test/new_relic/version_number_test.rb +46 -0
- data/test/test_helper.rb +7 -30
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
- data/ui/controllers/newrelic_controller.rb +17 -3
- data/ui/helpers/newrelic_helper.rb +44 -15
- data/ui/views/layouts/newrelic_default.rhtml +7 -8
- data/ui/views/newrelic/_sample.rhtml +5 -2
- data/ui/views/newrelic/_segment.rhtml +1 -1
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +4 -4
- data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
- data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
- data/ui/views/newrelic/explain_sql.rhtml +2 -5
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/index.rhtml +21 -13
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/show_sample.rhtml +18 -3
- data/ui/views/newrelic/stylesheets/style.css +39 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +192 -70
- data/README +0 -136
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
- data/lib/new_relic/agent/samplers/cpu.rb +0 -29
- data/lib/new_relic/agent/samplers/memory.rb +0 -53
- data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
- data/lib/new_relic/agent/synchronize.rb +0 -40
- data/lib/new_relic/config/merb.rb +0 -35
- data/lib/new_relic/config/rails.rb +0 -114
- data/lib/new_relic/config.rb +0 -279
- data/lib/new_relic/shim_agent.rb +0 -96
- data/test/new_relic/agent/model_fixture.rb +0 -15
- data/test/new_relic/agent/tc_active_record.rb +0 -90
- data/test/new_relic/agent/tc_agent.rb +0 -148
- data/test/new_relic/agent/tc_controller.rb +0 -77
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
- data/test/new_relic/agent/tc_error_collector.rb +0 -127
- data/test/new_relic/agent/tc_stats_engine.rb +0 -218
- data/test/new_relic/agent/tc_synchronize.rb +0 -37
- data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
- data/test/new_relic/tc_config.rb +0 -36
- data/test/new_relic/tc_environment.rb +0 -94
- data/test/new_relic/tc_stats.rb +0 -141
data/README
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
= New Relic RPM
|
2
|
-
|
3
|
-
* http://www.newrelic.com
|
4
|
-
|
5
|
-
New Relic RPM is a Ruby performance management system, developed by
|
6
|
-
New Relic, Inc. RPM provides you with deep information about the
|
7
|
-
performance of your Ruby on Rails or Merb application as it runs in
|
8
|
-
production. The New Relic Agent is distributed as a either a Rails
|
9
|
-
plugin or a Gem, both hosted on RubyForge.
|
10
|
-
|
11
|
-
The New Relic Agent runs in one of two modes:
|
12
|
-
|
13
|
-
* Developer Mode : Adds a web interface mapped to /newrelic to your
|
14
|
-
application for showing detailed performance metrics on a page by
|
15
|
-
page basis.
|
16
|
-
|
17
|
-
* Production Mode : Low overhead instrumentation that captures
|
18
|
-
detailed information on your application running in production and
|
19
|
-
transmits them to rpm.newrelic.com where you can monitor them in
|
20
|
-
real time.
|
21
|
-
|
22
|
-
=== Developer Mode
|
23
|
-
|
24
|
-
Developer mode is on by default when you run your application in the
|
25
|
-
development environment (but not when it runs in other environments.)
|
26
|
-
When running in developer mode, RPM will track the performance of
|
27
|
-
every http request serviced by your application, and store in memory
|
28
|
-
this information for the last 100 http transactions.
|
29
|
-
|
30
|
-
When running in Developer Mode, the RPM will also add a few pages to
|
31
|
-
your application that allow you to analyze this performance
|
32
|
-
information. (Don't worry - those pages are not added to your
|
33
|
-
application's routes when you run in production mode.)
|
34
|
-
|
35
|
-
To view this performance information, including detailed SQL statement
|
36
|
-
analysis, open '/newrelic' in your web application. For instance if
|
37
|
-
you are running mongrel or thin on port 3000, enter the following into
|
38
|
-
your browser:
|
39
|
-
|
40
|
-
http://localhost:3000/newrelic
|
41
|
-
|
42
|
-
=== Production Mode
|
43
|
-
|
44
|
-
To monitor your applications in production, create an account at
|
45
|
-
http://newrelic.com/get-RPM.html
|
46
|
-
|
47
|
-
When your application runs in the production environment, the New
|
48
|
-
Relic agent runs in production mode. It connects to the New Relic RPM
|
49
|
-
service and sends deep performance data to the RPM service for your
|
50
|
-
analysis. To view this data, login to http://rpm.newrelic.com.
|
51
|
-
|
52
|
-
NOTE: You must have a valid account and license key to view this data
|
53
|
-
online. When you sign up for an account at www.newrelic.com, you will
|
54
|
-
be provided with a license key, as well as a default configuration
|
55
|
-
file for New Relic RPM. You can either paste your license key into
|
56
|
-
your existing configuration file, config/newrelic.yml, or you can
|
57
|
-
replace that config file with the one included in your welcome email.
|
58
|
-
|
59
|
-
== Installation
|
60
|
-
|
61
|
-
RPM requires an agent be installed in the application as either a
|
62
|
-
Rails plug-in or a gem. Both are available on RubyForge--instructions
|
63
|
-
below.
|
64
|
-
|
65
|
-
=== Git your RPM on!
|
66
|
-
|
67
|
-
The agent is also available on Github under newrelic/rpm. As of March,
|
68
|
-
2009, we keep the latest release on the master, the edge on a working
|
69
|
-
branch, and previous releases with tags. Fork away!
|
70
|
-
|
71
|
-
=== Requirements:
|
72
|
-
|
73
|
-
Ruby 1.8.6
|
74
|
-
Rails 1.2.6 or above
|
75
|
-
Merb 1.0 or above
|
76
|
-
|
77
|
-
=== Rails Plug-In Installation
|
78
|
-
|
79
|
-
script/plugin install http://newrelic.rubyforge.org/svn/newrelic_rpm
|
80
|
-
|
81
|
-
=== Gem Installation
|
82
|
-
|
83
|
-
sudo gem install newrelic_rpm
|
84
|
-
|
85
|
-
For Rails, edit environment.rb and add to the initalizer block:
|
86
|
-
|
87
|
-
config.gem "newrelic_rpm"
|
88
|
-
|
89
|
-
The Developer Mode is unavailable when using the gem on Rails versions
|
90
|
-
prior to 2.0.
|
91
|
-
|
92
|
-
== Merb Support
|
93
|
-
|
94
|
-
To monitor a merb app install the newrelic_rpm gem and add
|
95
|
-
|
96
|
-
dependency 'newrelic_rpm'
|
97
|
-
|
98
|
-
to your init.rb file.
|
99
|
-
|
100
|
-
Current features implemented:
|
101
|
-
|
102
|
-
* Standard monitoring, overview pages
|
103
|
-
* Error capturing
|
104
|
-
* Full Active Record instrumentation, including SQL explains
|
105
|
-
* Very limited Data Mapper instrumentation
|
106
|
-
* Transaction Traces are implemented but will not be very useful
|
107
|
-
with Data Mapper until more work is done with the Data Mapper
|
108
|
-
instrumentation
|
109
|
-
|
110
|
-
Still under development:
|
111
|
-
|
112
|
-
* Developer Mode
|
113
|
-
* Data Mapper bindings
|
114
|
-
|
115
|
-
Also some of the instrumentation has been implemented with method
|
116
|
-
chaining, a mechanism that truly goes against the merb way. This was
|
117
|
-
necessary in some cases where the API’s were not yet available or
|
118
|
-
understood well enough to use. Converting these to hook methods using
|
119
|
-
the Merb public API is a work in progress.
|
120
|
-
|
121
|
-
== Support
|
122
|
-
|
123
|
-
Reach out to us--and to fellow RPM users--at
|
124
|
-
http://support.newrelic.com. There you'll find documentation, FAQs,
|
125
|
-
and forums where you can submit suggestions and discuss RPM with New
|
126
|
-
Relic staff and other users.
|
127
|
-
|
128
|
-
Find a bug? E-mail support@newrelic.com, or post it to
|
129
|
-
support.newrelic.com.
|
130
|
-
|
131
|
-
For other support channels, see http://www.newrelic.com/support.
|
132
|
-
|
133
|
-
Thank you, and may your application scale to infinity plus one.
|
134
|
-
|
135
|
-
Lew Cirne, Founder and CEO
|
136
|
-
New Relic, Inc.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module NewRelic::Agent
|
2
|
-
class CPUSampler
|
3
|
-
def initialize
|
4
|
-
|
5
|
-
agent = NewRelic::Agent.instance
|
6
|
-
|
7
|
-
agent.stats_engine.add_sampled_metric("CPU/User Time") do | stats |
|
8
|
-
t = Process.times
|
9
|
-
@last_utime ||= t.utime
|
10
|
-
|
11
|
-
utime = t.utime
|
12
|
-
stats.record_data_point(utime - @last_utime) if (utime - @last_utime) >= 0
|
13
|
-
@last_utime = utime
|
14
|
-
end
|
15
|
-
|
16
|
-
agent.stats_engine.add_sampled_metric("CPU/System Time") do | stats |
|
17
|
-
t = Process.times
|
18
|
-
@last_stime ||= t.stime
|
19
|
-
|
20
|
-
stime = t.stime
|
21
|
-
stats.record_data_point(stime - @last_stime) if (stime - @last_stime) >= 0
|
22
|
-
@last_stime = stime
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# CPU sampling like this doesn't work for jruby
|
29
|
-
NewRelic::Agent::CPUSampler.new unless defined? Java
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module NewRelic::Agent
|
2
|
-
class MemorySampler
|
3
|
-
def initialize
|
4
|
-
if RUBY_PLATFORM =~ /java/
|
5
|
-
platform = %x[uname -s].downcase
|
6
|
-
else
|
7
|
-
platform = RUBY_PLATFORM.downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
# macos, linux, solaris
|
11
|
-
if platform =~ /darwin|linux/
|
12
|
-
@ps = "ps -o rsz"
|
13
|
-
elsif platform =~ /freebsd/
|
14
|
-
@ps = "ps -o rss"
|
15
|
-
elsif platform =~ /solaris/
|
16
|
-
@ps = "/usr/bin/ps -o rss -p"
|
17
|
-
end
|
18
|
-
if !@ps
|
19
|
-
NewRelic::Config.instance.log.warn "Unsupported platform for getting memory: #{platform}"
|
20
|
-
else
|
21
|
-
@broken = false
|
22
|
-
|
23
|
-
agent = NewRelic::Agent.instance
|
24
|
-
agent.stats_engine.add_sampled_metric("Memory/Physical") do |stats|
|
25
|
-
if !@broken
|
26
|
-
begin
|
27
|
-
process = $$
|
28
|
-
memory = `#{@ps} #{process}`.split("\n")[1].to_f / 1024
|
29
|
-
|
30
|
-
# if for some reason the ps command doesn't work on the resident os,
|
31
|
-
# then don't execute it any more.
|
32
|
-
if memory >= 0
|
33
|
-
stats.record_data_point memory
|
34
|
-
else
|
35
|
-
NewRelic::Agent.instance.log.error "Error attempting to determine resident memory for pid #{process} (got result of #{memory}, this process = #{$$}). Disabling this metric."
|
36
|
-
NewRelic::Agent.instance.log.error "Faulty command: `#{@ps}`"
|
37
|
-
@broken = true
|
38
|
-
end
|
39
|
-
rescue Exception => e
|
40
|
-
if e.is_a? Errno::ENOMEM
|
41
|
-
NewRelic::Agent.instance.log.error "Got OOM trying to determine process memory usage"
|
42
|
-
else
|
43
|
-
raise e
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
NewRelic::Agent::MemorySampler.new
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# NewRelic Instrumentation for Mongrel - tracks the queue length of the mongrel server
|
2
|
-
if defined? Mongrel::HttpServer
|
3
|
-
|
4
|
-
agent = NewRelic::Agent.instance
|
5
|
-
mongrel = nil;
|
6
|
-
ObjectSpace.each_object(Mongrel::HttpServer) do |mongrel_instance|
|
7
|
-
# should only be one mongrel instance in the vm
|
8
|
-
if mongrel
|
9
|
-
agent.log.info("Discovered multiple mongrel instances in one Ruby VM. "+
|
10
|
-
"This is unexpected and might affect the Accuracy of the Mongrel Request Queue metric.")
|
11
|
-
end
|
12
|
-
|
13
|
-
mongrel = mongrel_instance
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
if mongrel
|
18
|
-
agent.stats_engine.add_sampled_metric("Mongrel/Queue Length") do |stats|
|
19
|
-
qsize = mongrel.workers.list.length
|
20
|
-
qsize -= 1 if NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.is_busy?
|
21
|
-
qsize = 0 if qsize < 0
|
22
|
-
stats.record_data_point qsize
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
|
2
|
-
module NewRelic::Agent
|
3
|
-
|
4
|
-
module Synchronize
|
5
|
-
def synchronize_sync
|
6
|
-
@_local_sync ||= Sync.new
|
7
|
-
|
8
|
-
@_local_sync.synchronize(:EX) do
|
9
|
-
yield
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def synchronize_mutex
|
15
|
-
@_local_mutex ||= Mutex.new
|
16
|
-
|
17
|
-
@_local_mutex.synchronize do
|
18
|
-
yield
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def synchronize_thread
|
24
|
-
old_val = Thread.critical
|
25
|
-
|
26
|
-
Thread.critical = true
|
27
|
-
|
28
|
-
begin
|
29
|
-
yield
|
30
|
-
ensure
|
31
|
-
Thread.critical = old_val
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
alias synchronize synchronize_mutex
|
37
|
-
alias synchronize_quick synchronize_mutex
|
38
|
-
alias synchronized_long synchronize_mutex
|
39
|
-
end
|
40
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class NewRelic::Config::Merb < NewRelic::Config
|
2
|
-
|
3
|
-
def app; :merb; end
|
4
|
-
|
5
|
-
def env
|
6
|
-
@env ||= ::Merb.env
|
7
|
-
end
|
8
|
-
def root
|
9
|
-
::Merb.root
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_stderr(msg)
|
13
|
-
STDERR.puts "NewRelic ~ " + msg
|
14
|
-
end
|
15
|
-
|
16
|
-
def start_plugin
|
17
|
-
::Merb::Plugins.add_rakefiles File.join(newrelic_root,"lib/tasks/all.rb")
|
18
|
-
|
19
|
-
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
20
|
-
::Merb::Plugins.config[:newrelic] = {
|
21
|
-
:config => self
|
22
|
-
}
|
23
|
-
|
24
|
-
::Merb::BootLoader.before_app_loads do
|
25
|
-
# require code that must be loaded before the application
|
26
|
-
end
|
27
|
-
|
28
|
-
if tracers_enabled?
|
29
|
-
::Merb::BootLoader.after_app_loads do
|
30
|
-
start_agent
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
class NewRelic::Config::Rails < NewRelic::Config
|
2
|
-
|
3
|
-
def app; :rails; end
|
4
|
-
|
5
|
-
def env
|
6
|
-
@env ||= RAILS_ENV
|
7
|
-
end
|
8
|
-
def root
|
9
|
-
RAILS_ROOT
|
10
|
-
end
|
11
|
-
|
12
|
-
def log_path
|
13
|
-
path = ::RAILS_DEFAULT_LOGGER.instance_eval do
|
14
|
-
File.dirname(@log.path) rescue File.dirname(@logdev.filename)
|
15
|
-
end rescue "#{root}/log"
|
16
|
-
File.expand_path(path)
|
17
|
-
end
|
18
|
-
|
19
|
-
def start_plugin(rails_config=nil)
|
20
|
-
if !tracers_enabled? || !start_agent
|
21
|
-
require 'new_relic/shim_agent'
|
22
|
-
else
|
23
|
-
install_developer_mode rails_config if developer_mode?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def install_developer_mode(rails_config)
|
28
|
-
controller_path = File.join(newrelic_root, 'ui', 'controllers')
|
29
|
-
helper_path = File.join(newrelic_root, 'ui', 'helpers')
|
30
|
-
|
31
|
-
if defined? ActiveSupport::Dependencies
|
32
|
-
Dir["#{helper_path}/*.rb"].each { |f| require f }
|
33
|
-
Dir["#{controller_path}/*.rb"].each { |f| require f }
|
34
|
-
elsif defined? Dependencies.load_paths
|
35
|
-
Dependencies.load_paths << controller_path
|
36
|
-
Dependencies.load_paths << helper_path
|
37
|
-
else
|
38
|
-
to_stderr "ERROR: Rails version #{(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : ''} too old for developer mode to work."
|
39
|
-
return
|
40
|
-
end
|
41
|
-
|
42
|
-
install_devmode_route
|
43
|
-
|
44
|
-
|
45
|
-
# If we have the config object then add the controller path to the list.
|
46
|
-
# Otherwise we have to assume the controller paths have already been
|
47
|
-
# set and we can just append newrelic.
|
48
|
-
|
49
|
-
if rails_config
|
50
|
-
rails_config.controller_paths << controller_path
|
51
|
-
else
|
52
|
-
current_paths = ActionController::Routing.controller_paths
|
53
|
-
if current_paths.nil? || current_paths.empty?
|
54
|
-
to_stderr "WARNING: Unable to modify the routes in this version of Rails. Developer mode not available."
|
55
|
-
end
|
56
|
-
current_paths << controller_path
|
57
|
-
end
|
58
|
-
|
59
|
-
#ActionController::Routing::Routes.reload! unless NewRelic::Config.instance['skip_developer_route']
|
60
|
-
|
61
|
-
# inform user that the dev edition is available if we are running inside
|
62
|
-
# a webserver process
|
63
|
-
if local_env.identifier
|
64
|
-
port = local_env.identifier.to_s =~ /^\d+/ ? ":#{local_env.identifier}" : ":port"
|
65
|
-
to_stderr "NewRelic Agent Developer Mode enabled."
|
66
|
-
to_stderr "To view performance information, go to http://localhost#{port}/newrelic"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
def install_devmode_route
|
73
|
-
# This is a monkey patch to inject the developer tool route into the
|
74
|
-
# parent app without requiring users to modify their routes. Of course this
|
75
|
-
# has the effect of adding a route indiscriminately which is frowned upon by
|
76
|
-
# some: http://www.ruby-forum.com/topic/126316#563328
|
77
|
-
ActionController::Routing::RouteSet.class_eval do
|
78
|
-
return false if self.instance_methods.include? 'draw_with_newrelic_map'
|
79
|
-
def draw_with_newrelic_map
|
80
|
-
draw_without_newrelic_map do | map |
|
81
|
-
map.named_route 'newrelic_developer', '/newrelic/:action/:id', :controller => 'newrelic' unless NewRelic::Config.instance['skip_developer_route']
|
82
|
-
yield map
|
83
|
-
end
|
84
|
-
end
|
85
|
-
alias_method_chain :draw, :newrelic_map
|
86
|
-
end
|
87
|
-
return true
|
88
|
-
end
|
89
|
-
|
90
|
-
# Collect the Rails::Info into an associative array as well as the list of plugins
|
91
|
-
def gather_info
|
92
|
-
i = [[:app, app]]
|
93
|
-
begin
|
94
|
-
begin
|
95
|
-
require 'rails/info'
|
96
|
-
rescue LoadError
|
97
|
-
require 'builtin/rails_info/rails/info'
|
98
|
-
end
|
99
|
-
i += ::Rails::Info.properties
|
100
|
-
rescue SecurityError, ScriptError, StandardError => e
|
101
|
-
log.debug "Unable to get the Rails info: #{e.inspect}"
|
102
|
-
end
|
103
|
-
|
104
|
-
plugins = Dir[File.expand_path(File.join(RAILS_ROOT,"vendor","plugins","*"))].collect { |p| File.basename p }
|
105
|
-
i << ['Plugin List', plugins]
|
106
|
-
|
107
|
-
# Look for a capistrano file indicating the current revision:
|
108
|
-
rev_file = File.expand_path(File.join(RAILS_ROOT, "REVISION"))
|
109
|
-
if File.readable?(rev_file) && File.size(rev_file) < 64
|
110
|
-
File.open(rev_file) { | file | i << ['Revision', file.read] } rescue nil
|
111
|
-
end
|
112
|
-
i
|
113
|
-
end
|
114
|
-
end
|