newrelic_rpm 2.12.3 → 2.13.0.beta3
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 +24 -2
- data/README.rdoc +172 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +2 -1
- data/install.rb +8 -45
- data/lib/new_relic/agent.rb +43 -30
- data/lib/new_relic/agent/agent.rb +699 -631
- data/lib/new_relic/agent/busy_calculator.rb +81 -81
- data/lib/new_relic/agent/error_collector.rb +9 -6
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +10 -5
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +13 -45
- data/lib/new_relic/agent/instrumentation/memcache.rb +15 -4
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +37 -29
- data/lib/new_relic/agent/instrumentation/rack.rb +20 -34
- data/lib/new_relic/agent/method_tracer.rb +9 -9
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +31 -31
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -5
- data/lib/new_relic/agent/stats_engine/samplers.rb +3 -0
- data/lib/new_relic/agent/transaction_sampler.rb +31 -15
- data/lib/new_relic/agent/worker_loop.rb +29 -28
- data/lib/new_relic/collection_helper.rb +4 -2
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +74 -114
- data/lib/new_relic/commands/install.rb +81 -0
- data/lib/new_relic/control.rb +54 -379
- data/lib/new_relic/control/configuration.rb +149 -0
- data/lib/new_relic/control/{external.rb → frameworks/external.rb} +2 -2
- data/lib/new_relic/control/{merb.rb → frameworks/merb.rb} +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +126 -0
- data/lib/new_relic/control/{rails3.rb → frameworks/rails3.rb} +11 -10
- data/lib/new_relic/control/{ruby.rb → frameworks/ruby.rb} +1 -1
- data/lib/new_relic/control/{sinatra.rb → frameworks/sinatra.rb} +2 -2
- data/lib/new_relic/control/instrumentation.rb +84 -0
- data/lib/new_relic/control/logging_methods.rb +74 -0
- data/lib/new_relic/control/profiling.rb +24 -0
- data/lib/new_relic/control/server_methods.rb +88 -0
- data/lib/new_relic/local_environment.rb +3 -3
- data/lib/new_relic/metric_parser.rb +13 -2
- data/lib/new_relic/metric_parser/active_record.rb +4 -1
- data/lib/new_relic/metric_parser/apdex.rb +53 -0
- data/lib/new_relic/metric_parser/controller.rb +13 -5
- data/lib/new_relic/metric_parser/mem_cache.rb +1 -1
- data/lib/new_relic/metric_parser/other_transaction.rb +21 -0
- data/lib/new_relic/metric_spec.rb +3 -3
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/developer_mode.rb +257 -0
- data/lib/new_relic/rack/metric_app.rb +56 -50
- data/lib/new_relic/rack/mongrel_rpm.ru +7 -6
- data/lib/new_relic/rack/newrelic.yml +4 -3
- data/lib/new_relic/rack_app.rb +2 -1
- data/lib/new_relic/recipes.rb +7 -7
- data/lib/new_relic/stats.rb +6 -14
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +2 -7
- data/lib/new_relic/transaction_sample.rb +17 -85
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +3 -3
- data/lib/newrelic_rpm.rb +5 -9
- data/newrelic.yml +26 -9
- data/newrelic_rpm.gemspec +67 -32
- data/test/config/newrelic.yml +5 -0
- data/test/config/test_control.rb +6 -8
- data/test/new_relic/agent/active_record_instrumentation_test.rb +5 -6
- data/test/new_relic/agent/agent_controller_test.rb +18 -4
- data/test/new_relic/agent/agent_test_controller.rb +1 -6
- data/test/new_relic/agent/busy_calculator_test.rb +2 -0
- data/test/new_relic/agent/collection_helper_test.rb +6 -6
- data/test/new_relic/agent/error_collector_test.rb +13 -21
- data/test/new_relic/agent/metric_data_test.rb +3 -6
- data/test/new_relic/agent/rpm_agent_test.rb +121 -117
- data/test/new_relic/agent/task_instrumentation_test.rb +128 -133
- data/test/new_relic/agent/transaction_sample_test.rb +176 -170
- data/test/new_relic/agent/worker_loop_test.rb +24 -18
- data/test/new_relic/control_test.rb +13 -3
- data/test/new_relic/deployments_api_test.rb +7 -7
- data/test/new_relic/environment_test.rb +1 -1
- data/test/new_relic/metric_parser_test.rb +58 -4
- data/test/new_relic/rack/episodes_test.rb +317 -0
- data/test/new_relic/stats_test.rb +3 -2
- data/test/test_contexts.rb +28 -0
- data/test/test_helper.rb +24 -5
- data/ui/helpers/{newrelic_helper.rb → developer_mode_helper.rb} +63 -23
- data/ui/views/layouts/newrelic_default.rhtml +6 -6
- data/ui/views/newrelic/_explain_plans.rhtml +4 -4
- data/ui/views/newrelic/_sample.rhtml +18 -17
- data/ui/views/newrelic/_segment.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +8 -8
- data/ui/views/newrelic/_show_sample_detail.rhtml +1 -1
- data/ui/views/newrelic/_show_sample_sql.rhtml +2 -2
- data/ui/views/newrelic/_sql_row.rhtml +8 -3
- data/ui/views/newrelic/_stack_trace.rhtml +9 -24
- data/ui/views/newrelic/_table.rhtml +1 -1
- data/ui/views/newrelic/explain_sql.rhtml +3 -2
- data/ui/views/newrelic/{images → file/images}/arrow-close.png +0 -0
- data/ui/views/newrelic/{images → file/images}/arrow-open.png +0 -0
- data/ui/views/newrelic/{images → file/images}/blue_bar.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/file_icon.png +0 -0
- data/ui/views/newrelic/{images → file/images}/gray_bar.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/{images → 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/{stylesheets → file/stylesheets}/style.css +0 -0
- data/ui/views/newrelic/index.rhtml +7 -5
- data/ui/views/newrelic/sample_not_found.rhtml +1 -1
- data/ui/views/newrelic/show_sample.rhtml +5 -6
- metadata +92 -34
- data/README.md +0 -138
- data/lib/new_relic/commands/new_relic_commands.rb +0 -30
- data/lib/new_relic/control/rails.rb +0 -151
- data/test/new_relic/agent/mock_ar_connection.rb +0 -40
- data/test/ui/newrelic_controller_test.rb +0 -14
- data/test/ui/newrelic_helper_test.rb +0 -53
- data/ui/controllers/newrelic_controller.rb +0 -220
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +0 -7288
- data/ui/views/newrelic/javascript/transaction_sample.js +0 -107
@@ -1,30 +0,0 @@
|
|
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
|
-
|
7
|
-
libdir = File.expand_path(File.join(File.dirname(__FILE__), '..','..'))
|
8
|
-
command_list = Dir[File.join(libdir,'new_relic','commands','*.rb')].map{|command| command =~ /.*\/(.*)\.rb/ && $1}
|
9
|
-
command_list.delete 'new_relic_commands'
|
10
|
-
extra = []
|
11
|
-
options = ARGV.options do |opts|
|
12
|
-
script_name = File.basename($0)
|
13
|
-
opts.banner = "Usage: #{__FILE__} #{ command_list.join(" | ")} [options]"
|
14
|
-
opts.separator "use -h to see detailed command options"
|
15
|
-
opts
|
16
|
-
end
|
17
|
-
extra = options.order!
|
18
|
-
command = extra.shift
|
19
|
-
if !command_list.include?(command)
|
20
|
-
STDERR.puts options
|
21
|
-
else
|
22
|
-
require File.join(libdir, 'new_relic','commands', command + ".rb")
|
23
|
-
command_class = NewRelic::Commands.const_get(command.capitalize)
|
24
|
-
begin
|
25
|
-
command_class.new(extra).run
|
26
|
-
rescue NewRelic::Commands::CommandFailure => failure
|
27
|
-
STDERR.puts failure.message
|
28
|
-
exit failure.exit_code
|
29
|
-
end
|
30
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
# Control subclass instantiated when Rails is detected. Contains
|
2
|
-
# Rails specific configuration, instrumentation, environment values,
|
3
|
-
# etc.
|
4
|
-
class NewRelic::Control::Rails < NewRelic::Control
|
5
|
-
|
6
|
-
def env
|
7
|
-
@env ||= RAILS_ENV.dup
|
8
|
-
end
|
9
|
-
def root
|
10
|
-
RAILS_ROOT
|
11
|
-
end
|
12
|
-
|
13
|
-
def log_path
|
14
|
-
path = super || ::RAILS_DEFAULT_LOGGER.instance_eval do
|
15
|
-
File.dirname(@log.path) rescue File.dirname(@logdev.filename)
|
16
|
-
end rescue File.join(root, 'log')
|
17
|
-
File.expand_path(path)
|
18
|
-
end
|
19
|
-
# In versions of Rails prior to 2.0, the rails config was only available to
|
20
|
-
# the init.rb, so it had to be passed on from there.
|
21
|
-
def init_config(options={})
|
22
|
-
rails_config=options[:config]
|
23
|
-
if !agent_enabled?
|
24
|
-
# Might not be running if it does not think mongrel, thin, passenger, etc
|
25
|
-
# is running, if it things it's a rake task, or if the agent_enabled is false.
|
26
|
-
::RAILS_DEFAULT_LOGGER.info "New Relic Agent not running."
|
27
|
-
else
|
28
|
-
::RAILS_DEFAULT_LOGGER.info "Starting the New Relic Agent."
|
29
|
-
install_developer_mode rails_config if developer_mode?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def install_developer_mode(rails_config)
|
34
|
-
return if @installed
|
35
|
-
@installed = true
|
36
|
-
controller_path = File.expand_path(File.join(newrelic_root, 'ui', 'controllers'))
|
37
|
-
helper_path = File.expand_path(File.join(newrelic_root, 'ui', 'helpers'))
|
38
|
-
|
39
|
-
if defined? ActiveSupport::Dependencies
|
40
|
-
Dir["#{helper_path}/*.rb"].each { |f| require f }
|
41
|
-
Dir["#{controller_path}/*.rb"].each { |f| require f }
|
42
|
-
elsif defined? Dependencies.load_paths
|
43
|
-
Dependencies.load_paths << controller_path
|
44
|
-
Dependencies.load_paths << helper_path
|
45
|
-
else
|
46
|
-
to_stdout "ERROR: Rails version #{::Rails::VERSION::STRING} too old for developer mode to work."
|
47
|
-
return
|
48
|
-
end
|
49
|
-
install_devmode_route
|
50
|
-
|
51
|
-
# If we have the config object then add the controller path to the list.
|
52
|
-
# Otherwise we have to assume the controller paths have already been
|
53
|
-
# set and we can just append newrelic.
|
54
|
-
|
55
|
-
if rails_config
|
56
|
-
rails_config.controller_paths << controller_path
|
57
|
-
else
|
58
|
-
current_paths = ActionController::Routing.controller_paths
|
59
|
-
if current_paths.nil? || current_paths.empty?
|
60
|
-
to_stdout "WARNING: Unable to modify the routes in this version of Rails. Developer mode not available."
|
61
|
-
end
|
62
|
-
current_paths << controller_path
|
63
|
-
end
|
64
|
-
|
65
|
-
def to_stdout(message)
|
66
|
-
::RAILS_DEFAULT_LOGGER.info(message)
|
67
|
-
rescue Exception => e
|
68
|
-
STDOUT.puts(message)
|
69
|
-
end
|
70
|
-
|
71
|
-
#ActionController::Routing::Routes.reload! unless NewRelic::Control.instance['skip_developer_route']
|
72
|
-
|
73
|
-
# inform user that the dev edition is available if we are running inside
|
74
|
-
# a webserver process
|
75
|
-
if @local_env.dispatcher_instance_id
|
76
|
-
port = @local_env.dispatcher_instance_id.to_s =~ /^\d+/ ? ":#{local_env.dispatcher_instance_id}" : ":port"
|
77
|
-
to_stdout "NewRelic Agent Developer Mode enabled."
|
78
|
-
to_stdout "To view performance information, go to http://localhost#{port}/newrelic"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def rails_version
|
83
|
-
@rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
|
84
|
-
end
|
85
|
-
|
86
|
-
protected
|
87
|
-
|
88
|
-
def install_devmode_route
|
89
|
-
# This is a monkey patch to inject the developer tool route into the
|
90
|
-
# parent app without requiring users to modify their routes. Of course this
|
91
|
-
# has the effect of adding a route indiscriminately which is frowned upon by
|
92
|
-
# some: http://www.ruby-forum.com/topic/126316#563328
|
93
|
-
ActionController::Routing::RouteSet.class_eval do
|
94
|
-
next if self.instance_methods.include? 'draw_with_newrelic_map'
|
95
|
-
def draw_with_newrelic_map
|
96
|
-
draw_without_newrelic_map do | map |
|
97
|
-
unless NewRelic::Control.instance['skip_developer_route']
|
98
|
-
map.named_route 'newrelic_developer', '/newrelic/:action/:id', :controller => 'newrelic'
|
99
|
-
map.named_route 'newrelic_file', '/newrelic/file/*file', :controller => 'newrelic', :action=>'file'
|
100
|
-
end
|
101
|
-
yield map
|
102
|
-
end
|
103
|
-
end
|
104
|
-
alias_method_chain :draw, :newrelic_map
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def rails_vendor_root
|
109
|
-
File.join(root,'vendor','rails')
|
110
|
-
end
|
111
|
-
|
112
|
-
# Collect the Rails::Info into an associative array as well as the list of plugins
|
113
|
-
def append_environment_info
|
114
|
-
local_env.append_environment_value('Rails version'){ ::Rails::VERSION::STRING }
|
115
|
-
if rails_version >= NewRelic::VersionNumber.new('2.2.0')
|
116
|
-
local_env.append_environment_value('Rails threadsafe') do
|
117
|
-
::Rails.configuration.action_controller.allow_concurrency == true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
local_env.append_environment_value('Rails Env') { ENV['RAILS_ENV'] }
|
121
|
-
if rails_version >= NewRelic::VersionNumber.new('2.1.0')
|
122
|
-
local_env.append_gem_list do
|
123
|
-
::Rails.configuration.gems.map do | gem |
|
124
|
-
version = (gem.respond_to?(:version) && gem.version) ||
|
125
|
-
(gem.specification.respond_to?(:version) && gem.specification.version)
|
126
|
-
gem.name + (version ? "(#{version})" : "")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
# The plugins is configured manually. If it's nil, it loads everything non-deterministically
|
130
|
-
if ::Rails.configuration.plugins
|
131
|
-
local_env.append_plugin_list { ::Rails.configuration.plugins }
|
132
|
-
else
|
133
|
-
::Rails.configuration.plugin_paths.each do |path|
|
134
|
-
local_env.append_plugin_list { Dir[File.join(path, '*')].collect{ |p| File.basename p if File.directory? p }.compact }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
else
|
138
|
-
# Rails prior to 2.1, can't get the gems. Find plugins in the default location
|
139
|
-
local_env.append_plugin_list do
|
140
|
-
Dir[File.join(root, 'vendor', 'plugins', '*')].collect{ |p| File.basename p if File.directory? p }.compact
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def install_shim
|
146
|
-
super
|
147
|
-
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
148
|
-
ActionController::Base.send :include, NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
class << self
|
4
|
-
def test_connection(config)
|
5
|
-
@connect ||= Connection.new
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Connection
|
11
|
-
attr_accessor :throw
|
12
|
-
attr_reader :disconnected
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@disconnected = false
|
16
|
-
@throw = false
|
17
|
-
end
|
18
|
-
|
19
|
-
def disconnect!()
|
20
|
-
@disconnected = true
|
21
|
-
end
|
22
|
-
|
23
|
-
def find()
|
24
|
-
# used to test that we've instrumented this...
|
25
|
-
end
|
26
|
-
|
27
|
-
def select_rows(s)
|
28
|
-
execute(s)
|
29
|
-
end
|
30
|
-
def execute(s)
|
31
|
-
fail "" if @throw
|
32
|
-
if s != "EXPLAIN #{::SQL_STATEMENT}"
|
33
|
-
fail "Unexpected sql statement #{s}"
|
34
|
-
end
|
35
|
-
s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
2
|
-
require 'newrelic_helper'
|
3
|
-
require 'active_record_fixtures'
|
4
|
-
|
5
|
-
class NewRelic::Agent::NewrelicControllerTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
# Clearly we need a functional test for the controller. For now
|
8
|
-
# I want to at least make sure the class loads in all versions of rails.
|
9
|
-
def test_controller_loading
|
10
|
-
NewrelicController
|
11
|
-
rescue
|
12
|
-
fail "Controller would not load:#{$!}"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
2
|
-
require 'newrelic_helper'
|
3
|
-
require 'active_record_fixtures'
|
4
|
-
|
5
|
-
class NewRelic::Agent::NewrelicHelperTest < Test::Unit::TestCase
|
6
|
-
include NewrelicHelper
|
7
|
-
|
8
|
-
def params
|
9
|
-
{}
|
10
|
-
end
|
11
|
-
|
12
|
-
def setup
|
13
|
-
super
|
14
|
-
ActiveRecordFixtures.setup
|
15
|
-
# setup instrumentation
|
16
|
-
NewRelic::Agent.manual_start
|
17
|
-
# let's get a real stack trace
|
18
|
-
begin
|
19
|
-
ActiveRecordFixtures::Order.find 0
|
20
|
-
rescue => e
|
21
|
-
@exception = e
|
22
|
-
return
|
23
|
-
end
|
24
|
-
flunk "should throw"
|
25
|
-
end
|
26
|
-
def teardown
|
27
|
-
ActiveRecordFixtures.teardown
|
28
|
-
NewRelic::Agent.instance.shutdown
|
29
|
-
super
|
30
|
-
end
|
31
|
-
def test_application_caller
|
32
|
-
assert_match /setup/, application_caller(@exception.backtrace)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_application_stack_trace__rails
|
36
|
-
assert_clean(application_stack_trace(@exception.backtrace, true), true)
|
37
|
-
end
|
38
|
-
def test_application_stack_trace__no_rails
|
39
|
-
assert_clean(application_stack_trace(@exception.backtrace, false), false)
|
40
|
-
end
|
41
|
-
def test_with_delimiter
|
42
|
-
assert_equal "123,456.123456", with_delimiter(123456.123456)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
def assert_clean(backtrace, rails=false)
|
47
|
-
if !rails
|
48
|
-
assert_equal 0, backtrace.grep('/rails/').size, backtrace.join("\n")
|
49
|
-
end
|
50
|
-
assert_equal 0, backtrace.grep(/trace/).size, backtrace.join("\n")
|
51
|
-
assert_equal 0, backtrace.grep(/newrelic_rpm\/agent/).size, backtrace.join("\n")
|
52
|
-
end
|
53
|
-
end
|
@@ -1,220 +0,0 @@
|
|
1
|
-
class NewrelicController < ActionController::Base
|
2
|
-
include NewrelicHelper
|
3
|
-
helper NewrelicHelper
|
4
|
-
|
5
|
-
# See http://wiki.rubyonrails.org/rails/pages/Safe+ERB:
|
6
|
-
# We don't need to worry about checking taintedness
|
7
|
-
def initialize(*args)
|
8
|
-
@skip_checking_tainted = true
|
9
|
-
super *args
|
10
|
-
end
|
11
|
-
|
12
|
-
# do not include any filters inside the application since there might be a conflict
|
13
|
-
if respond_to? :filter_chain
|
14
|
-
filters = filter_chain.collect do |f|
|
15
|
-
if f.respond_to? :filter
|
16
|
-
# rails 2.0
|
17
|
-
f.filter
|
18
|
-
elsif f.respond_to? :method
|
19
|
-
# rails 2.1
|
20
|
-
f.method
|
21
|
-
else
|
22
|
-
fail "Unknown filter class. Please send this exception to support@newrelic.com"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
skip_filter filters
|
26
|
-
end
|
27
|
-
|
28
|
-
# for this controller, the views are located in a different directory from
|
29
|
-
# the application's views.
|
30
|
-
view_path = File.join(File.dirname(__FILE__), '..', 'views')
|
31
|
-
if respond_to? :append_view_path # rails 2.1+
|
32
|
-
self.append_view_path view_path
|
33
|
-
elsif respond_to? :view_paths # rails 2.0+
|
34
|
-
self.view_paths << view_path
|
35
|
-
else # rails <2.0
|
36
|
-
self.template_root = view_path
|
37
|
-
end
|
38
|
-
|
39
|
-
layout "newrelic_default"
|
40
|
-
|
41
|
-
write_inheritable_attribute('do_not_trace', true)
|
42
|
-
|
43
|
-
def profile
|
44
|
-
NewRelic::Control.instance.profiling = params['start'] == 'true'
|
45
|
-
get_samples
|
46
|
-
redirect_to :action => 'index'
|
47
|
-
end
|
48
|
-
|
49
|
-
def file
|
50
|
-
file_name=Array(params[:file]).join
|
51
|
-
file_name=~/^.*[.]([^.]*)$/
|
52
|
-
ext=$1
|
53
|
-
case ext
|
54
|
-
when 'css' then
|
55
|
-
forward_to_file '/newrelic/stylesheets/', 'text/css'
|
56
|
-
when 'gif','jpg','png' then
|
57
|
-
forward_to_file '/newrelic/images/', "image/#{ext}"
|
58
|
-
when 'js' then
|
59
|
-
forward_to_file '/newrelic/javascript/', 'text/javascript'
|
60
|
-
else
|
61
|
-
raise "Unknown type '#{ext}' (#{file_name})"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def index
|
66
|
-
get_samples
|
67
|
-
end
|
68
|
-
|
69
|
-
def threads
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
def reset
|
74
|
-
NewRelic::Agent.instance.transaction_sampler.reset!
|
75
|
-
redirect_to :action => 'index'
|
76
|
-
end
|
77
|
-
|
78
|
-
def show_sample_detail
|
79
|
-
show_sample_data
|
80
|
-
end
|
81
|
-
|
82
|
-
def show_sample_summary
|
83
|
-
show_sample_data
|
84
|
-
end
|
85
|
-
|
86
|
-
def show_sample_sql
|
87
|
-
show_sample_data
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
def explain_sql
|
92
|
-
get_segment
|
93
|
-
|
94
|
-
render :action => "sample_not_found" and return unless @sample
|
95
|
-
|
96
|
-
@sql = @segment[:sql]
|
97
|
-
@trace = @segment[:backtrace]
|
98
|
-
|
99
|
-
if NewRelic::Agent.agent.record_sql == :obfuscated
|
100
|
-
@obfuscated_sql = @segment.obfuscated_sql
|
101
|
-
end
|
102
|
-
|
103
|
-
explanations = @segment.explain_sql
|
104
|
-
if explanations
|
105
|
-
@explanation = explanations.first
|
106
|
-
if !@explanation.blank?
|
107
|
-
first_row = @explanation.first
|
108
|
-
# Show the standard headers if it looks like a mysql explain plan
|
109
|
-
# Otherwise show blank headers
|
110
|
-
if first_row.length < NewRelic::MYSQL_EXPLAIN_COLUMNS.length
|
111
|
-
@row_headers = nil
|
112
|
-
else
|
113
|
-
@row_headers = NewRelic::MYSQL_EXPLAIN_COLUMNS
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# show the selected source file with the highlighted selected line
|
120
|
-
def show_source
|
121
|
-
@filename = params[:file]
|
122
|
-
line_number = params[:line].to_i
|
123
|
-
|
124
|
-
if !File.readable?(@filename)
|
125
|
-
@source="<p>Unable to read #{@filename}.</p>"
|
126
|
-
return
|
127
|
-
end
|
128
|
-
begin
|
129
|
-
file = File.new(@filename, 'r')
|
130
|
-
rescue => e
|
131
|
-
@source="<p>Unable to access the source file #{@filename} (#{e.message}).</p>"
|
132
|
-
return
|
133
|
-
end
|
134
|
-
@source = ""
|
135
|
-
|
136
|
-
@source << "<pre>"
|
137
|
-
file.each_line do |line|
|
138
|
-
# place an anchor 6 lines above the selected line (if the line # < 6)
|
139
|
-
if file.lineno == line_number - 6
|
140
|
-
@source << "</pre><pre id = 'selected_line'>"
|
141
|
-
@source << line.rstrip
|
142
|
-
@source << "</pre><pre>"
|
143
|
-
|
144
|
-
# highlight the selected line
|
145
|
-
elsif file.lineno == line_number
|
146
|
-
@source << "</pre><pre class = 'selected_source_line'>"
|
147
|
-
@source << line.rstrip
|
148
|
-
@source << "</pre><pre>"
|
149
|
-
else
|
150
|
-
@source << line
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
|
157
|
-
# root path is relative to plugin newrelic_rpm/ui/views directory.
|
158
|
-
def forward_to_file(root_path, content_type='ignored anyway')
|
159
|
-
file = File.expand_path(File.join(__FILE__,"../../views", root_path, params[:file]))
|
160
|
-
last_modified = File.mtime(file)
|
161
|
-
date_check = request.respond_to?(:headers) ? request.headers['if-modified-since'] : request.env['HTTP_IF_MODIFIED_SINCE']
|
162
|
-
if date_check && Time.parse(date_check) >= last_modified
|
163
|
-
expires_in 24.hours
|
164
|
-
head :not_modified,
|
165
|
-
:last_modified => last_modified,
|
166
|
-
:type => 'text/plain'
|
167
|
-
else
|
168
|
-
response.headers['Last-Modified'] = last_modified.to_formatted_s(:rfc822)
|
169
|
-
expires_in 24.hours
|
170
|
-
send_file file, :content_type => mime_type_from_extension(file), :disposition => 'inline' #, :filename => File.basename(file)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def show_sample_data
|
175
|
-
get_sample
|
176
|
-
|
177
|
-
render :action => "sample_not_found" and return unless @sample
|
178
|
-
|
179
|
-
@request_params = @sample.params[:request_params] || {}
|
180
|
-
@custom_params = @sample.params[:custom_params] || {}
|
181
|
-
|
182
|
-
controller_metric = @sample.root_segment.called_segments.first.metric_name
|
183
|
-
|
184
|
-
controller_segments = controller_metric.split('/')
|
185
|
-
@sample_controller_name = controller_segments[1..-2].join('/').camelize+"Controller"
|
186
|
-
@sample_action_name = controller_segments[-1].underscore
|
187
|
-
|
188
|
-
render :action => :show_sample
|
189
|
-
end
|
190
|
-
|
191
|
-
def get_samples
|
192
|
-
@samples = NewRelic::Agent.instance.transaction_sampler.samples.select do |sample|
|
193
|
-
sample.params[:path] != nil
|
194
|
-
end
|
195
|
-
|
196
|
-
return @samples = @samples.sort{|x,y| y.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)').duration <=>
|
197
|
-
x.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)').duration} if params[:h]
|
198
|
-
return @samples = @samples.sort{|x,y| x.params[:uri] <=> y.params[:uri]} if params[:u]
|
199
|
-
@samples = @samples.reverse
|
200
|
-
end
|
201
|
-
|
202
|
-
def get_sample
|
203
|
-
get_samples
|
204
|
-
sample_id = params[:id].to_i
|
205
|
-
@samples.each do |s|
|
206
|
-
if s.sample_id == sample_id
|
207
|
-
@sample = stripped_sample(s)
|
208
|
-
return
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def get_segment
|
214
|
-
get_sample
|
215
|
-
return unless @sample
|
216
|
-
|
217
|
-
segment_id = params[:segment].to_i
|
218
|
-
@segment = @sample.find_segment(segment_id)
|
219
|
-
end
|
220
|
-
end
|