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, #cross_app_encoding_bytes, #cross_process_id, #error_collector, #events, #metric_rules, #obfuscator, #record_sql, #service, #sql_sampler, #stats_engine, #thread_profiler, #transaction_rules, #transaction_sampler

Attributes included from InstanceMethods::Connect

#connect_attempts

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, timings

Methods included from InstanceMethods

#after_fork, #end_transaction, #forked?, #merge_data_from, #pop_trace_execution_flag, #push_trace_execution_flag, #record_transaction, #reset_stats, #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

#add_rules_to_engine, #apdex_f, #connect_retry_period, #connect_settings, #connect_to_server, #connected?, #disconnect, #disconnected?, #environment_for_connect, #finish_setup, #handle_license_error, #handle_unrecoverable_agent_error, #log_collector_messages, #log_connection!, #log_error, #note_connect_failure, #query_server_for_configuration, #should_connect?

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, #defer_for_resque?, #disabled?, #has_correct_license_key?, #has_license_key?, #install_exit_handler, #log_app_names, #log_dispatcher, #log_environment, #log_if, #log_startup, #log_unless, #log_version_and_pid, #monitoring?, #using_forking_dispatcher?, #using_sinatra?, #weird_ruby?

Constructor Details

#initializeAgent

Returns a new instance of Agent.



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
52
53
54
55
56
57
58
59
60
# File 'lib/new_relic/agent/agent.rb', line 25

def initialize
  @launch_time = Time.now

  @events                = NewRelic::Agent::EventListener.new
  @stats_engine          = NewRelic::Agent::StatsEngine.new
  @transaction_sampler   = NewRelic::Agent::TransactionSampler.new
  @sql_sampler           = NewRelic::Agent::SqlSampler.new
  @thread_profiler       = NewRelic::Agent::ThreadProfiler.new
  @cross_app_monitor     = NewRelic::Agent::CrossAppMonitor.new(@events)
  @error_collector       = NewRelic::Agent::ErrorCollector.new
  @transaction_rules     = NewRelic::Agent::RulesEngine.new
  @metric_rules          = NewRelic::Agent::RulesEngine.new

  @connect_state = :pending
  @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