module OneApm::Collector::CollectorService::ServerMethods
Public Instance Methods
convert_to_ip_address(host)
click to toggle source
Check to see if we need to look up the IP address If it's an IP address already, we pass it through. If it's nil, or localhost, we don't bother. Otherwise, use `resolve_ip_address` to find one
# File lib/one_apm/collector/collector/server_methods.rb, line 38 def convert_to_ip_address(host) # here we leave it as a host name since the cert verification # needs it in host form return host if OneApm::Manager.config[:ssl] # We won't talk directly to the host, so no need to resolve if proxy configured return host if OneApm::Manager.config[:proxy_host] return nil if host.nil? || host.downcase == "localhost" ip = resolve_ip_address(host) OneApm::Manager.logger.debug "Resolved #{host} to #{ip}" ip end
proxy_server()
click to toggle source
a new instances of the proxy server - this passes through if there is no proxy, otherwise it has proxy configuration information pulled from the config file
# File lib/one_apm/collector/collector/server_methods.rb, line 18 def proxy_server @proxy_server ||= OneApm::Support::ProxyServer.new(Manager.config[:proxy_host], OneApm::Manager.config[:proxy_port], OneApm::Manager.config[:proxy_user], OneApm::Manager.config[:proxy_pass]) end
resolve_ip_address(host)
click to toggle source
Look up the ip address of the host using the pure ruby lookup to prevent blocking. If that fails, fall back to the regular IPSocket library. Return nil if we can't find the host ip address and don't have a good default.
# File lib/one_apm/collector/collector/server_methods.rb, line 55 def resolve_ip_address(host) Resolv.getaddress(host) rescue => e OneApm::Manager.logger.warn("DNS Error caching IP address:", e) begin OneApm::Manager.logger.debug("Trying native DNS lookup since Resolv failed") IPSocket.getaddress(host) rescue => e OneApm::Manager.logger.error("Could not look up server address: #{e}") nil end end
server()
click to toggle source
# File lib/one_apm/collector/collector/server_methods.rb, line 11 def server @remote_server ||= server_from_host end
server_from_host(hostname=nil)
click to toggle source
turns a hostname into an ip address and returns a OneApm::Support::Server
that contains the configuration info
# File lib/one_apm/collector/collector/server_methods.rb, line 27 def server_from_host(hostname=nil) host = hostname || OneApm::Manager.config[:host] # if the host is not an IP address, turn it into one OneApm::Support::Server.new(host, OneApm::Manager.config[:port], convert_to_ip_address(host)) end