module OneApm::Agent::Agent::Connect
Attributes
connect_attempts[RW]
Public Instance Methods
apdex_f()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 84 def apdex_f (4 * OneApm::Manager.config[:apdex_t]).to_f end
client_ip()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 114 def client_ip @ip ||= OneApm::Agent::IP.get end
connect_retry_period()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 27 def connect_retry_period [600, connect_attempts * 60].min end
connect_settings()
click to toggle source
# 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()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 92 def connect_to_server @service.connect(connect_settings) end
connected?()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 15 def connected? @connect_state == :connected end
disconnect()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 10 def disconnect @connect_state = :disconnected true end
disconnected?()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 19 def disconnected? @connect_state == :disconnected end
environment_for_connect()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 52 def generate_environment_report @environment_report = environment_for_connect end
handle_license_error(error)
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 39 def handle_license_error(error) OneApm::Manager.logger.error( \ error.message, \ "Visit oneapm.com to obtain a valid license key, or to upgrade your account.") disconnect end
handle_unrecoverable_agent_error(error)
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 46 def handle_unrecoverable_agent_error(error) OneApm::Manager.logger.error(error.message) disconnect shutdown end
local_host()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 110 def local_host @local_host ||= OneApm::Agent::Hostname.get end
log_collector_messages(messages)
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 127 def log_collector_messages(messages) messages.each do |message| OneApm::Manager.logger.send(message['level'].downcase, message['message']) end end
log_connection!(config_data)
click to toggle source
# 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? log_collector_messages(config_data['messages']) end end
log_error(error)
click to toggle source
# 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()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 31 def note_connect_failure self.connect_attempts += 1 end
query_server_for_configuration()
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 88 def query_server_for_configuration finish_setup(connect_to_server) end
sanitize_environment_report()
click to toggle source
# 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)
click to toggle source
# File lib/one_apm/agent/agent/connect.rb, line 23 def should_connect?(force = false) force || (!connected? && !disconnected?) end