lib/new_relic/agent/agent.rb in newrelic_rpm-2.12.2.beta vs lib/new_relic/agent/agent.rb in newrelic_rpm-2.12.2.beta2
- old
+ new
@@ -72,18 +72,16 @@
return if !control.agent_enabled? or
!control.monitor_mode? or
@connected == false or
@worker_thread && @worker_thread.alive?
- log.debug "Detected that the worker thread is not running in #$$. Restarting."
+ log.info "Starting the worker thread in #$$ after forking."
# Clear out stats that are left over from parent process
reset_stats
- # Don't ever check to see if this is a spawner. If we're in a forked process
- # I'm pretty sure we're not also forking new instances.
- start_worker_thread(options.merge(:check_for_spawner => false))
+ start_worker_thread(options)
@stats_engine.start_sampler_thread
end
# True if we have initialized and completed 'start'
def started?
@@ -163,11 +161,11 @@
NewRelic::Agent.logger
end
# Start up the agent. This verifies that the agent_enabled? is
# true and initializes the sampler based on the current
- # controluration settings. Then it will fire up the background
+ # configuration settings. Then it will fire up the background
# thread for sending data to the server if applicable.
def start
if started?
control.log! "Agent Started Already!", :error
return
@@ -206,24 +204,29 @@
@random_sample = sampler_config.fetch('random_sample', false)
log.warn "Agent is configured to send raw SQL to RPM service" if @record_sql == :raw
# Initialize transaction sampler
@transaction_sampler.random_sampling = @random_sample
- if control.monitor_mode?
- if !control.license_key
- control.log! "No license key found. Please edit your newrelic.yml file and insert your license key.", :error
- elsif control.license_key.length != 40
- control.log! "Invalid license key: #{control.license_key}", :error
- else
- # Do the connect in the foreground if we are in sync mode
- NewRelic::Agent.disable_all_tracing { connect(:keep_retrying => false) } if control.sync_startup
-
- # Start the event loop and initiate connection if necessary
- start_worker_thread
-
- # Our shutdown handler needs to run after other shutdown handlers
- # that may be doing things like running the app (hello sinatra).
+ case
+ when !control.monitor_mode?
+ log.warn "Agent configured not to send data in this environment - edit newrelic.yml to change this"
+ when !control.license_key
+ log.error "No license key found. Please edit your newrelic.yml file and insert your license key."
+ when control.license_key.length != 40
+ log.error "Invalid license key: #{control.license_key}"
+ when [:passenger, :unicorn].include?(control.dispatcher)
+ log.info "Connecting workers after forking."
+ else
+ # Do the connect in the foreground if we are in sync mode
+ NewRelic::Agent.disable_all_tracing { connect(:keep_retrying => false) } if control.sync_startup
+
+ # Start the event loop and initiate connection if necessary
+ start_worker_thread
+
+ # Our shutdown handler needs to run after other shutdown handlers
+ # that may be doing things like running the app (hello sinatra).
+ if control.send_data_on_exit
if RUBY_VERSION =~ /rubinius/i
list = at_exit { shutdown }
# move the shutdown handler to the front of the list, to
# execute last:
list.unshift(list.pop)
@@ -346,37 +349,23 @@
# return with the connection set to nil. This ensures we may try again
# later (default true).
# * <tt>force_reconnect => true</tt> if you want to establish a new connection
# to the server before running the worker loop. This means you get a separate
# agent run and RPM sees it as a separate instance (default is false).
- # * <tt>:check_for_spawner => false</tt> to omit the check to see if we are
- # an application spawner. We detect the spawner and stop the agent so we don't
- # report stats from a spawner. You don't want to do this check if you _know_
- # you are not in a spawner (default is true).
-
def connect(options)
# Don't proceed if we already connected (@connected=true) or if we tried
# to connect and were rejected with prejudice because of a license issue
# (@connected=false).
return if !@connected.nil? && !options[:force_reconnect]
keep_retrying = options[:keep_retrying].nil? || options[:keep_retrying]
- check_for_spawner = options[:check_for_spawner].nil? || options[:check_for_spawner]
# wait a few seconds for the web server to boot, necessary in development
connect_retry_period = keep_retrying ? 10 : 0
connect_attempts = 0
@agent_id = nil
begin
sleep connect_retry_period.to_i
- # Running in the Passenger or Unicorn spawners?
- if check_for_spawner && $0 =~ /ApplicationSpawner|^unicorn\S* master/
- log.debug "Process is master spawner (#$0) -- don't connect to RPM service"
- @connected = nil
- return
- else
- log.debug "Connecting Process to RPM: #$0"
- end
environment = control['send_environment_info'] != false ? control.local_env.snapshot : []
log.debug "Connecting with validation seed/token: #{control.validate_seed}/#{control.validate_token}" if control.validate_seed
@agent_id ||= invoke_remote :start, @local_host, {
:pid => $$,
:launch_time => @launch_time.to_f,