Class: NewRelic::Agent::Agent

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods, Configuration::Instance
Includes:
InstanceMethods, BrowserMonitoring
Defined in:
lib/new_relic/agent/agent.rb

Overview

The Agent is a singleton that is instantiated when the plugin is activated. It collects performance data from ruby applications in realtime as the application runs, and periodically sends that data to the NewRelic server.

Direct Known Subclasses

ShimAgent

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Attribute Summary

Attributes included from InstanceMethods

#beacon_configuration, #error_collector, #metric_ids, #obfuscator, #record_sql, #service, #sql_sampler, #stats_engine, #transaction_sampler, #url_rules

Attributes included from InstanceMethods::Connect

#connect_attempts, #connect_retry_period

Instance Method Summary collapse

Methods included from Configuration::Instance

config, reset_config

Methods included from ClassMethods

instance

Methods included from BrowserMonitoring

beacon_url, browser_monitoring_app_time, browser_monitoring_queue_time, browser_monitoring_start_time, browser_monitoring_transaction_name, #browser_timing_footer, #browser_timing_header, clamp_to_positive, current_metric_frame, insert_mobile_response_header, mobile_header_found_in?, obfuscate

Methods included from InstanceMethods

#after_fork, #connected?, #end_transaction, #forked?, #log, #merge_data_from, #pop_trace_execution_flag, #push_trace_execution_flag, #record_transaction, #reset_stats, #serialize, #set_record_sql, #set_record_tt, #shutdown, #start, #start_transaction, #started?, #unsent_errors_size, #unsent_timeslice_data, #unsent_traces_size

Methods included from InstanceMethods::Connect

#apdex_f, #connect_settings, #connect_to_server, #disconnect, #environment_for_connect, #finish_setup, #get_retry_period, #handle_license_error, #increment_retry_period!, #log_collector_messages, #log_connection!, #log_error, #log_seed_token, #query_server_for_configuration, #should_keep_retrying?, #should_retry?, #tried_to_connect?, #validate_settings

Methods included from InstanceMethods::StartWorkerThread

#catch_errors, #create_and_run_worker_loop, #deferred_work!, #handle_force_disconnect, #handle_force_restart, #handle_other_error, #handle_server_connection_problem, #log_worker_loop_start

Methods included from InstanceMethods::Start

#already_started?, #check_config_and_start_agent, #connect_in_foreground, #correct_license_length, #disabled?, #has_correct_license_key?, #has_license_key?, #install_exit_handler, #log_app_names, #log_dispatcher, #log_if, #log_unless, #log_version_and_pid, #monitoring?, #notify_log_file_location, #using_forking_dispatcher?, #using_sinatra?, #weird_ruby?

Constructor Details

#initializeAgent

Returns a new instance of Agent.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/new_relic/agent/agent.rb', line 22

def initialize
  @launch_time = Time.now

  @metric_ids = {}
  @stats_engine = NewRelic::Agent::StatsEngine.new
  @transaction_sampler = NewRelic::Agent::TransactionSampler.new
  @sql_sampler = NewRelic::Agent::SqlSampler.new
  @error_collector = NewRelic::Agent::ErrorCollector.new
  @connect_attempts = 0

  @last_harvest_time = Time.now
  @obfuscator = lambda {|sql| NewRelic::Agent::Database.default_sql_obfuscator(sql) }
  @forked = false

  # FIXME: temporary work around for RUBY-839
  if Agent.config[:monitor_mode]
    @service = NewRelic::Agent::NewRelicService.new
  end

  txn_tracer_enabler = Proc.new do
    if NewRelic::Agent.config[:'transaction_tracer.enabled'] ||
        NewRelic::Agent.config[:developer_mode]
      @stats_engine.transaction_sampler = @transaction_sampler
    else
      @stats_engine.transaction_sampler = nil
    end
  end
  Agent.config.register_callback(:'transaction_tracer.enabled', &txn_tracer_enabler)
  Agent.config.register_callback(:developer_mode, &txn_tracer_enabler)
end