Module: OneApm::Agent::Agent::Connect
- Included in:
- OneApm::Agent::Agent
- Defined in:
- lib/one_apm/agent/agent/connect.rb
Instance Attribute Summary collapse
-
#connect_attempts ⇒ Object
Returns the value of attribute connect_attempts.
Instance Method Summary collapse
- #apdex_f ⇒ Object
- #client_ip ⇒ Object
- #connect_retry_period ⇒ Object
- #connect_settings ⇒ Object
- #connect_to_server ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #disconnected? ⇒ Boolean
- #environment_for_connect ⇒ Object
- #finish_setup(config_data) ⇒ Object
- #generate_environment_report ⇒ Object
- #handle_license_error(error) ⇒ Object
- #handle_unrecoverable_agent_error(error) ⇒ Object
- #local_host ⇒ Object
- #log_collector_messages(messages) ⇒ Object
- #log_connection!(config_data) ⇒ Object
- #log_error(error) ⇒ Object
- #note_connect_failure ⇒ Object
- #query_server_for_configuration ⇒ Object
- #sanitize_environment_report ⇒ Object
- #should_connect?(force = false) ⇒ Boolean
Instance Attribute Details
#connect_attempts ⇒ Object
Returns the value of attribute connect_attempts.
8 9 10 |
# File 'lib/one_apm/agent/agent/connect.rb', line 8 def connect_attempts @connect_attempts end |
Instance Method Details
#apdex_f ⇒ Object
84 85 86 |
# File 'lib/one_apm/agent/agent/connect.rb', line 84 def apdex_f (4 * OneApm::Manager.config[:apdex_t]).to_f end |
#client_ip ⇒ Object
114 115 116 |
# File 'lib/one_apm/agent/agent/connect.rb', line 114 def client_ip @ip ||= OneApm::Agent::IP.get end |
#connect_retry_period ⇒ Object
27 28 29 |
# File 'lib/one_apm/agent/agent/connect.rb', line 27 def connect_retry_period [600, connect_attempts * 60].min end |
#connect_settings ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/one_apm/agent/agent/connect.rb', line 66 def connect_settings sanitize_environment_report { :pid => $$, :host => local_host, :tier_name => OneApm::Manager.config.tier_names, :app_name => OneApm::Manager.config.app_name, :language => 'ruby', :labels => OneApm::Manager.config.parsed_labels, :agent_version => OneApm::VERSION::STRING, :environment => @environment_report, :settings => OneApm::Manager.config.to_notified_hash, :high_security => OneApm::Manager.config[:high_security], :identifier => "ruby:#{local_host}", :clientIP => client_ip } end |
#connect_to_server ⇒ Object
92 93 94 |
# File 'lib/one_apm/agent/agent/connect.rb', line 92 def connect_to_server @service.connect(connect_settings) end |
#connected? ⇒ Boolean
15 16 17 |
# File 'lib/one_apm/agent/agent/connect.rb', line 15 def connected? @connect_state == :connected end |
#disconnect ⇒ Object
10 11 12 13 |
# File 'lib/one_apm/agent/agent/connect.rb', line 10 def disconnect @connect_state = :disconnected true end |
#disconnected? ⇒ Boolean
19 20 21 |
# File 'lib/one_apm/agent/agent/connect.rb', line 19 def disconnected? @connect_state == :disconnected end |
#environment_for_connect ⇒ Object
56 57 58 |
# File 'lib/one_apm/agent/agent/connect.rb', line 56 def environment_for_connect OneApm::Manager.config[:send_environment_info] ? Array(EnvironmentReport.new) : [] end |
#finish_setup(config_data) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/one_apm/agent/agent/connect.rb', line 96 def finish_setup(config_data) return if config_data == nil @service.agent_id = config_data['agent_run_id'] if @service OneApm::Manager.logger.debug "Server provided config: #{config_data.inspect}" server_config = OneApm::Configuration::ServerSource.new(config_data, OneApm::Manager.config) OneApm::Manager.config.update_config(server_config) log_connection!(config_data) if @service @transaction_rules = OneApm::Support::RulesEngine.create_transaction_rules(config_data) @stats_engine.metric_rules = OneApm::Support::RulesEngine.create_metric_rules(config_data) @external_rename_rules = OneApm::Support::RenameRulesEngine.create_or_update_external_rules(config_data) end |
#generate_environment_report ⇒ Object
52 53 54 |
# File 'lib/one_apm/agent/agent/connect.rb', line 52 def generate_environment_report @environment_report = environment_for_connect end |
#handle_license_error(error) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/one_apm/agent/agent/connect.rb', line 39 def handle_license_error(error) OneApm::Manager.logger.error( \ error., \ "Visit oneapm.com to obtain a valid license key, or to upgrade your account.") disconnect end |
#handle_unrecoverable_agent_error(error) ⇒ Object
46 47 48 49 50 |
# File 'lib/one_apm/agent/agent/connect.rb', line 46 def handle_unrecoverable_agent_error(error) OneApm::Manager.logger.error(error.) disconnect shutdown end |
#local_host ⇒ Object
110 111 112 |
# File 'lib/one_apm/agent/agent/connect.rb', line 110 def local_host @local_host ||= OneApm::Agent::Hostname.get end |
#log_collector_messages(messages) ⇒ Object
127 128 129 130 131 |
# File 'lib/one_apm/agent/agent/connect.rb', line 127 def () .each do || OneApm::Manager.logger.send(['level'].downcase, ['message']) end end |
#log_connection!(config_data) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/one_apm/agent/agent/connect.rb', line 118 def log_connection!(config_data) OneApm::Manager.logger.debug "Connected to OneApm Service at #{@service.collector.name}" OneApm::Manager.logger.debug "Agent Run = #{@service.agent_id}." OneApm::Manager.logger.debug "Connection data = #{config_data.inspect}" if config_data['messages'] && config_data['messages'].any? (config_data['messages']) end end |
#log_error(error) ⇒ Object
35 36 37 |
# File 'lib/one_apm/agent/agent/connect.rb', line 35 def log_error(error) OneApm::Manager.logger.error "Error establishing connection with OneApm Service at #{@service.server}:", error end |
#note_connect_failure ⇒ Object
31 32 33 |
# File 'lib/one_apm/agent/agent/connect.rb', line 31 def note_connect_failure self.connect_attempts += 1 end |
#query_server_for_configuration ⇒ Object
88 89 90 |
# File 'lib/one_apm/agent/agent/connect.rb', line 88 def query_server_for_configuration finish_setup(connect_to_server) end |
#sanitize_environment_report ⇒ Object
60 61 62 63 64 |
# File 'lib/one_apm/agent/agent/connect.rb', line 60 def sanitize_environment_report if !@service.valid_to_marshal?(@environment_report) @environment_report = [] end end |
#should_connect?(force = false) ⇒ Boolean
23 24 25 |
# File 'lib/one_apm/agent/agent/connect.rb', line 23 def should_connect?(force = false) force || (!connected? && !disconnected?) end |