Class: NewRelic::Control::Rails
Overview
Control subclass instantiated when Rails is detected. Contains Rails specific configuration, instrumentation, environment values, etc.
Instance Attribute Summary
#local_env, #log_file
Instance Method Summary
collapse
#[], #[]=, #add_instrumentation, #agent_enabled?, #apdex_t, #api_server, #app, #app_names, #capture_params, #developer_mode?, #dispatcher, #dispatcher_instance_id, #fetch, format_message, #http_connection, #init_plugin, #install_instrumentation, instance, #license_key, #load_samplers, #log, #log!, #monitor_mode?, #multi_threaded?, #post_size_limit, #profiling=, #profiling?, #profiling_available?, #proxy_server, #server, #server_from_host, #settings, #start_agent, #to_s, #use_ssl?, #use_textmate?, #verify_certificate?
Instance Method Details
6
7
8
|
# File 'lib/new_relic/control/rails.rb', line 6
def env
@env ||= RAILS_ENV.dup
end
|
#init_config(options = {}) ⇒ Object
In versions of Rails prior to 2.0, the rails config was only available to the init.rb, so it had to be passed on from there.
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/new_relic/control/rails.rb', line 21
def init_config(options={})
rails_config=options[:config]
if !agent_enabled?
RAILS_DEFAULT_LOGGER.info "New Relic Agent not running."
else
RAILS_DEFAULT_LOGGER.info "Starting the New Relic Agent."
install_developer_mode rails_config if developer_mode?
end
end
|
#install_developer_mode(rails_config) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/new_relic/control/rails.rb', line 33
def install_developer_mode(rails_config)
return if @installed
@installed = true
controller_path = File.expand_path(File.join(newrelic_root, 'ui', 'controllers'))
helper_path = File.expand_path(File.join(newrelic_root, 'ui', 'helpers'))
if defined? ActiveSupport::Dependencies
Dir["#{helper_path}/*.rb"].each { |f| require f }
Dir["#{controller_path}/*.rb"].each { |f| require f }
elsif defined? Dependencies.load_paths
Dependencies.load_paths << controller_path
Dependencies.load_paths << helper_path
else
to_stdout "ERROR: Rails version #{::Rails::VERSION::STRING} too old for developer mode to work."
return
end
install_devmode_route
if rails_config
rails_config.controller_paths << controller_path
else
current_paths = ActionController::Routing.controller_paths
if current_paths.nil? || current_paths.empty?
to_stdout "WARNING: Unable to modify the routes in this version of Rails. Developer mode not available."
end
current_paths << controller_path
end
def to_stdout(message)
::RAILS_DEFAULT_LOGGER.info(message)
rescue Exception => e
STDOUT.puts(message)
end
if @local_env.dispatcher_instance_id
port = @local_env.dispatcher_instance_id.to_s =~ /^\d+/ ? ":#{local_env.dispatcher_instance_id}" : ":port"
to_stdout "NewRelic Agent Developer Mode enabled."
to_stdout "To view performance information, go to http://localhost#{port}/newrelic"
end
end
|
13
14
15
16
17
18
|
# File 'lib/new_relic/control/rails.rb', line 13
def log_path
path = ::RAILS_DEFAULT_LOGGER.instance_eval do
File.dirname(@log.path) rescue File.dirname(@logdev.filename)
end rescue "#{root}/log"
File.expand_path(path)
end
|
#rails_version ⇒ Object
82
83
84
|
# File 'lib/new_relic/control/rails.rb', line 82
def rails_version
@rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
end
|
9
10
11
|
# File 'lib/new_relic/control/rails.rb', line 9
def root
RAILS_ROOT
end
|
#to_stdout(message) ⇒ Object
65
66
67
68
69
|
# File 'lib/new_relic/control/rails.rb', line 65
def to_stdout(message)
::RAILS_DEFAULT_LOGGER.info(message)
rescue Exception => e
STDOUT.puts(message)
end
|