lib/new_relic/agent/agent.rb in newrelic_rpm-3.9.7.266 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.9.8.273
- old
+ new
@@ -18,15 +18,17 @@
require 'new_relic/agent/database'
require 'new_relic/agent/commands/agent_command_router'
require 'new_relic/agent/event_listener'
require 'new_relic/agent/cross_app_monitor'
require 'new_relic/agent/synthetics_monitor'
+require 'new_relic/agent/synthetics_event_buffer'
require 'new_relic/agent/transaction_event_aggregator'
require 'new_relic/agent/custom_event_aggregator'
require 'new_relic/agent/sampler_collection'
require 'new_relic/agent/javascript_instrumentor'
require 'new_relic/agent/vm/monotonic_gc_profiler'
+require 'new_relic/agent/utilization_data'
require 'new_relic/environment_report'
module NewRelic
module Agent
@@ -50,14 +52,15 @@
@sql_sampler = NewRelic::Agent::SqlSampler.new
@agent_command_router = NewRelic::Agent::Commands::AgentCommandRouter.new(@events)
@cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events)
@synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events)
@error_collector = NewRelic::Agent::ErrorCollector.new
+ @utilization_data = NewRelic::Agent::UtilizationData.new
@transaction_rules = NewRelic::Agent::RulesEngine.new
@harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
- @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events)
@monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new
+ @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events)
@harvester = NewRelic::Agent::Harvester.new(@events)
@after_fork_lock = Mutex.new
@transaction_event_aggregator = NewRelic::Agent::TransactionEventAggregator.new(@events)
@@ -581,10 +584,11 @@
end
# Never allow any data type to be reported more frequently than once
# per second.
MIN_ALLOWED_REPORT_PERIOD = 1.0
+ UTILIZATION_REPORT_PERIOD = 30 * 60 # every half hour
def report_period_for(method)
config_key = "data_report_periods.#{method}".to_sym
period = Agent.config[config_key]
if !period
@@ -612,10 +616,19 @@
::NewRelic::Agent.logger.clear_already_logged
end
@event_loop.fire_every(Agent.config[:data_report_period], :report_data)
@event_loop.fire_every(report_period_for(:analytic_event_data), :report_event_data)
@event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
+
+ if Agent.config[:collect_utilization] && !in_resque_child_process?
+ @event_loop.on(:report_utilization_data) do
+ transmit_utilization_data
+ end
+ @event_loop.fire(:report_utilization_data)
+ @event_loop.fire_every(UTILIZATION_REPORT_PERIOD, :report_utilization_data)
+ end
+
@event_loop.run
end
# Handles the case where the server tells us to restart -
# this clears the data, clears connection attempts, and
@@ -880,10 +893,11 @@
case endpoint
when :metric_data then @stats_engine
when :transaction_sample_data then @transaction_sampler
when :error_data then @error_collector
when :analytic_event_data then @transaction_event_aggregator
+ when :custom_event_data then @custom_event_aggregator
when :sql_trace_data then @sql_sampler
end
end
def merge_data_for_endpoint(endpoint, data)
@@ -1041,13 +1055,17 @@
harvest_and_send_from_container(@error_collector, :error_data)
end
def harvest_and_send_analytic_event_data
harvest_and_send_from_container(@transaction_event_aggregator, :analytic_event_data)
- harvest_and_send_from_container(@custom_event_aggregator, :analytic_event_data)
+ harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
end
+ def harvest_and_send_utilization_data
+ harvest_and_send_from_container(@utilization_data, :utilization_data)
+ end
+
def check_for_and_handle_agent_commands
begin
@agent_command_router.check_for_and_handle_agent_commands
rescue ForceRestartException, ForceDisconnectException
raise
@@ -1069,21 +1087,31 @@
transmit_data_already_locked
end
end
def transmit_event_data
+ transmit_single_data_type(:harvest_and_send_analytic_event_data, "TransactionEvent")
+ end
+
+ def transmit_utilization_data
+ transmit_single_data_type(:harvest_and_send_utilization_data, "UtilizationData")
+ end
+
+ def transmit_single_data_type(harvest_method, supportability_name)
now = Time.now
- ::NewRelic::Agent.logger.debug "Sending analytics data to New Relic Service"
+ msg = "Sending #{harvest_method.to_s.gsub("harvest_and_send_", "")} to New Relic Service"
+ ::NewRelic::Agent.logger.debug msg
+
harvest_lock.synchronize do
@service.session do # use http keep-alive
- harvest_and_send_analytic_event_data
+ self.send(harvest_method)
end
end
ensure
duration = (Time.now - now).to_f
- NewRelic::Agent.record_metric('Supportability/TransactionEventHarvest', duration)
+ NewRelic::Agent.record_metric("Supportability/#{supportability_name}Harvest", duration)
end
# This method is expected to only be called with the harvest_lock
# already held
def transmit_data_already_locked
@@ -1121,9 +1149,10 @@
@service.request_timeout = 10
@events.notify(:before_shutdown)
transmit_data
transmit_event_data
+ transmit_utilization_data if NewRelic::Agent.config[:collect_utilization]
if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
::NewRelic::Agent.logger.debug "Sending New Relic service agent run shutdown message"
@service.shutdown(Time.now.to_f)
else