lib/new_relic/agent/agent.rb in newrelic_rpm-3.4.0.beta1 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.4.0.beta2
- old
+ new
@@ -2,11 +2,10 @@
require 'net/https'
require 'net/http'
require 'logger'
require 'zlib'
require 'stringio'
-require 'new_relic/data_serialization'
require 'new_relic/agent/new_relic_service'
require 'new_relic/agent/pipe_service'
module NewRelic
module Agent
@@ -153,10 +152,11 @@
# or we didn't attempt a connection because this is the master process
if channel_id = options[:report_to_channel]
@service = NewRelic::Agent::PipeService.new(channel_id)
@connected_pid = $$
+ @metric_ids = {}
end
# log.debug "Agent received after_fork notice in #$$: [#{control.agent_enabled?}; monitor=#{control.monitor_mode?}; connected: #{@connected.inspect}; thread=#{@worker_thread.inspect}]"
return if !control.agent_enabled? or
!control.monitor_mode? or
@@ -442,13 +442,10 @@
@last_harvest_time = Time.now
@launch_time = Time.now
end
private
-# def collector
-# @collector ||= control.collector
-# end
# All of this module used to be contained in the
# start_worker_thread method - this is an artifact of
# refactoring and can be moved, renamed, etc at will
module StartWorkerThread
@@ -483,11 +480,11 @@
# Creates the worker loop and loads it with the instructions
# it should run every @report_period seconds
def create_and_run_worker_loop
@worker_loop = WorkerLoop.new
@worker_loop.run(@report_period) do
- save_or_transmit_data
+ transmit_data
end
end
# Handles the case where the server tells us to restart -
# this clears the data, clears connection attempts, and
@@ -867,11 +864,11 @@
control.merge_server_side_config(config_data) if @server_side_config_enabled
config_transaction_tracer
log_connection!(config_data)
configure_transaction_tracer!(config_data['collect_traces'], config_data['sample_rate'])
- configure_error_collector!(config_data['collect_errors'])
+ configure_error_collector!(config_data['error_collector.enabled'])
end
# Logs when we connect to the server, for debugging purposes
# - makes sure we know if an agent has not connected
def log_connection!(config_data)
@@ -1007,12 +1004,10 @@
# note - exceptions are logged in invoke_remote. If an exception is encountered here,
# then the metric data is downsampled for another
# transmission later
def harvest_and_send_timeslice_data
now = Time.now
- NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote').record_data_point(0.0)
- NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote/metric_data').record_data_point(0.0)
harvest_timeslice_data(now)
# In this version of the protocol, we get back an assoc array of spec to id.
metric_specs_and_ids = @service.metric_data(@last_harvest_time.to_f,
now.to_f,
@unsent_timeslice_data.values)
@@ -1110,25 +1105,17 @@
# 20 instances to prevent leakage
@unsent_errors = []
end
end
- def save_or_transmit_data
- if NewRelic::DataSerialization.should_send_data?
- log.debug "Sending data to New Relic Service"
- NewRelic::Agent.load_data unless NewRelic::Control.instance.disable_serialization?
- harvest_and_send_errors
- harvest_and_send_slowest_sample
- harvest_and_send_slowest_sql
- harvest_and_send_timeslice_data
- else
- log.debug "Serializing agent data to disk"
- NewRelic::Agent.save_data
- end
+ def transmit_data
+ log.debug "Sending data to New Relic Service"
+ harvest_and_send_errors
+ harvest_and_send_slowest_sample
+ harvest_and_send_slowest_sql
+ harvest_and_send_timeslice_data
rescue => e
- NewRelic::Control.instance.disable_serialization = true
- NewRelic::Control.instance.log.warn("Disabling serialization: #{e.message}")
retry_count ||= 0
retry_count += 1
retry unless retry_count > 1
raise e
ensure
@@ -1144,10 +1131,10 @@
# disconnect, so that the parent process can continue to send data
def graceful_disconnect
if @connected
begin
@service.request_timeout = 10
- save_or_transmit_data
+ transmit_data
if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
log.debug "Sending New Relic service agent run shutdown message"
@service.shutdown(Time.now.to_f)
else
log.debug "This agent connected from parent process #{@connected_pid}--not sending shutdown"