lib/new_relic/agent/agent.rb in newrelic_rpm-3.7.0.177 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.7.1.180

- old
+ new

@@ -8,10 +8,11 @@ require 'logger' require 'zlib' require 'stringio' require 'new_relic/agent/sampled_buffer' require 'new_relic/agent/autostart' +require 'new_relic/agent/harvester' require 'new_relic/agent/new_relic_service' require 'new_relic/agent/pipe_service' require 'new_relic/agent/configuration/manager' require 'new_relic/agent/database' require 'new_relic/agent/commands/agent_command_router' @@ -48,10 +49,11 @@ @error_collector = NewRelic::Agent::ErrorCollector.new @transaction_rules = NewRelic::Agent::RulesEngine.new @request_sampler = NewRelic::Agent::RequestSampler.new(@events) @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events) @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events) + @harvester = NewRelic::Agent::Harvester.new(@events) @connect_state = :pending @connect_attempts = 0 @environment_report = nil @@ -158,10 +160,12 @@ # had not connected. # * <tt>:keep_retrying => false</tt> if we try to initiate a new # connection, this tells me to only try it once so this method returns # quickly if there is some kind of latency with the server. def after_fork(options={}) + @harvester.mark_started + Agent.config.apply_config(NewRelic::Agent::Configuration::ManualSource.new(options), 1) if channel_id = options[:report_to_channel] @service = NewRelic::Agent::PipeService.new(channel_id) if connected? @@ -198,38 +202,52 @@ # loop if it exists and is running. # # Options: # :force_send => (true/false) # force the agent to send data def shutdown(options={}) - run_loop_before_exit = Agent.config[:force_send] return if not started? + ::NewRelic::Agent.logger.info "Starting Agent shutdown" + + stop_worker_loop + trap_signals_for_litespeed + untraced_graceful_disconnect + revert_to_default_configuration + + @started = nil + Control.reset + end + + def revert_to_default_configuration + NewRelic::Agent.config.remove_config do |config| + config.class == NewRelic::Agent::Configuration::ManualSource || + config.class == NewRelic::Agent::Configuration::ServerSource + end + end + + def stop_worker_loop if @worker_loop - @worker_loop.run_task if run_loop_before_exit + @worker_loop.run_task if Agent.config[:force_send] @worker_loop.stop end + end - ::NewRelic::Agent.logger.info "Starting Agent shutdown" - + def trap_signals_for_litespeed # if litespeed, then ignore all future SIGUSR1 - it's # litespeed trying to shut us down if Agent.config[:dispatcher] == :litespeed Signal.trap("SIGUSR1", "IGNORE") Signal.trap("SIGTERM", "IGNORE") end + end + def untraced_graceful_disconnect begin NewRelic::Agent.disable_all_tracing do graceful_disconnect end rescue => e ::NewRelic::Agent.logger.error e end - NewRelic::Agent.config.remove_config do |config| - config.class == NewRelic::Agent::Configuration::ManualSource || - config.class == NewRelic::Agent::Configuration::ServerSource - end - @started = nil - Control.reset end # Tells the statistics engine we are starting a new transaction def start_transaction @stats_engine.start_transaction