Class: NewRelic::Control
- Inherits:
-
Object
- Object
- NewRelic::Control
- Extended by:
- ClassMethods
- Includes:
- Configuration, Instrumentation, LoggingMethods, Profiling, ServerMethods
- Defined in:
- lib/new_relic/control.rb,
lib/new_relic/control/profiling.rb,
lib/new_relic/control/configuration.rb,
lib/new_relic/control/server_methods.rb,
lib/new_relic/control/instrumentation.rb,
lib/new_relic/control/logging_methods.rb
Overview
The Control is a singleton responsible for the startup and initialization sequence. The initializer uses a LocalEnvironment to detect the framework and instantiates the framework specific subclass.
The Control also implements some of the public API for the agent.
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods, Configuration, Frameworks, Instrumentation, LoggingMethods, Profiling, ServerMethods Classes: ProxyServer, Server
Instance Attribute Summary collapse
-
#env ⇒ Object
writeonly
The env is the setting used to identify which section of the newrelic.yml to load.
-
#local_env ⇒ Object
readonly
Returns the value of attribute local_env.
Attributes included from LoggingMethods
Instance Method Summary collapse
-
#agent_enabled? ⇒ Boolean
True if dev mode or monitor mode are enabled, and we are running inside a valid dispatcher like mongrel or passenger.
- #app ⇒ Object (also: #framework)
-
#init_plugin(options = {}) ⇒ Object
Initialize the plugin/gem and start the agent.
-
#start_agent ⇒ Object
Install the real agent into the Agent module, and issue the start command.
- #to_s ⇒ Object
Methods included from ClassMethods
Methods included from Instrumentation
#_delayed_instrumentation, #add_instrumentation, #install_instrumentation, #install_shim, #load_instrumentation_files, #load_samplers
Methods included from ServerMethods
#api_server, #convert_to_ip_address, #http_connection, #proxy_server, #server, #server_from_host
Methods included from Configuration
#[], #[]=, #apdex_t, #app_names, #capture_params, #developer_mode?, #dispatcher, #dispatcher_instance_id, #episodes_enabled?, #fetch, #license_key, #merge_defaults, #merge_options, #monitor_mode?, #multi_threaded?, #post_size_limit, #send_data_on_exit, #settings, #sync_startup, #use_ssl?, #use_textmate?, #validate_seed, #validate_token, #verify_certificate?
Methods included from LoggingMethods
#log, #log!, #log_file_name, #log_path, #setup_log, #should_log?, #to_stdout
Methods included from Profiling
#profiling=, #profiling?, #profiling_available?
Instance Attribute Details
#env=(value) ⇒ Object (writeonly)
The env is the setting used to identify which section of the newrelic.yml to load. This defaults to a framework specific value, such as ENV but can be overridden as long as you set it before calling #init_plugin
36 37 38 |
# File 'lib/new_relic/control.rb', line 36 def env=(value) @env = value end |
#local_env ⇒ Object (readonly)
Returns the value of attribute local_env.
38 39 40 |
# File 'lib/new_relic/control.rb', line 38 def local_env @local_env end |
Instance Method Details
#agent_enabled? ⇒ Boolean
True if dev mode or monitor mode are enabled, and we are running inside a valid dispatcher like mongrel or passenger. Can be overridden by NEWRELIC_ENABLE env variable, monitor_daemons config option when true, or agent_enabled config option when true or false.
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/new_relic/control.rb', line 148 def agent_enabled? return false if !developer_mode? && !monitor_mode? return self['agent_enabled'].to_s =~ /true|on|yes/i if !self['agent_enabled'].nil? && self['agent_enabled'] != 'auto' return false if ENV['NEWRELIC_ENABLE'].to_s =~ /false|off|no/i return true if self['monitor_daemons'].to_s =~ /true|on|yes/i return true if ENV['NEWRELIC_ENABLE'].to_s =~ /true|on|yes/i # When in 'auto' mode the agent is enabled if there is a known # dispatcher running return true if @local_env.dispatcher != nil end |
#app ⇒ Object Also known as: framework
159 160 161 |
# File 'lib/new_relic/control.rb', line 159 def app @local_env.framework end |
#init_plugin(options = {}) ⇒ Object
Initialize the plugin/gem and start the agent. This does the necessary configuration based on the framework environment and determines whether or not to start the agent. If the agent is not going to be started then it loads the agent shim which has stubs for all the external api.
This may be invoked multiple times, as long as you don’t attempt to uninstall the agent after it has been started.
If the plugin is initialized and it determines that the agent is not enabled, it will skip starting it and install the shim. But if you later call this with :agent_enabled => true
, then it will install the real agent and start it.
What determines whether the agent is launched is the result of calling agent_enabled? This will indicate whether the instrumentation should/will be installed. If we’re in a mode where tracers are not installed then we should not start the agent.
Subclasses are not allowed to override, but must implement init_config({}) which is called one or more times.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/new_relic/control.rb', line 95 def init_plugin(={}) ['app_name'] = ENV['NEWRELIC_APP_NAME'] if ENV['NEWRELIC_APP_NAME'] require 'new_relic/agent' # Load the DJ injection now. If you do it sooner, DJ might not be loaded and # you'll miss it. require 'new_relic/delayed_job_injection' # Merge the stringified options into the config as overrides: logger_override = .delete(:log) environment_name = .delete(:env) and self.env = environment_name dispatcher = .delete(:dispatcher) and @local_env.dispatcher = dispatcher dispatcher_instance_id = .delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id # Clear out the settings, if they've already been loaded. It may be that # between calling init_plugin the first time and the second time, the env # has been overridden @settings = nil settings () if logger_override @log = logger_override # Try to grab the log filename @log_file = @log.instance_eval { @logdev.filename rescue nil } end # An artifact of earlier implementation, we put both #add_method_tracer and #trace_execution # methods in the module methods. Module.send :include, NewRelic::Agent::MethodTracer::ClassMethods Module.send :include, NewRelic::Agent::MethodTracer::InstanceMethods init_config() NewRelic::Agent.agent = NewRelic::Agent::Agent.instance if agent_enabled? && !NewRelic::Agent.instance.started? setup_log unless logger_override start_agent install_instrumentation load_samplers unless self['disable_samplers'] local_env.gather_environment_info append_environment_info elsif !agent_enabled? install_shim end end |
#start_agent ⇒ Object
Install the real agent into the Agent module, and issue the start command.
140 141 142 |
# File 'lib/new_relic/control.rb', line 140 def start_agent NewRelic::Agent.agent.start end |
#to_s ⇒ Object
164 165 166 |
# File 'lib/new_relic/control.rb', line 164 def to_s "Control[#{self.app}]" end |