class Wavefront::Writer::Proxy

Everything specific to writing points to a Wavefront proxy, in native Wavefront format, to a socket. (The original and, once, only way to send points.)

Public Instance Methods

close() click to toggle source

Close the connection described by the @conn instance variable.

# File lib/wavefront-sdk/writers/proxy.rb, line 30
def close
  return if opts[:noop]

  logger.log('Closing connection to proxy.', :debug)
  conn.close
end
open() click to toggle source

Open a connection to a socket to a Wavefront proxy, putting the descriptor in instance variable @conn. @return [TCPSocket]

# File lib/wavefront-sdk/writers/proxy.rb, line 17
def open
  if opts[:noop]
    logger.log('No-op requested. Not opening connection to proxy.')
    return true
  end

  port = creds[:port] || default_port
  logger.log("Connecting to #{creds[:proxy]}:#{port}.", :debug)
  open_socket(creds[:proxy], port)
end
validate_credentials(creds) click to toggle source
# File lib/wavefront-sdk/writers/proxy.rb, line 37
def validate_credentials(creds)
  return true if creds.key?(:proxy) && creds[:proxy]

  raise(Wavefront::Exception::CredentialError,
        'credentials must contain proxy address')
end

Private Instance Methods

_send_point(point) click to toggle source

@param point [String] point or points in native Wavefront format. @raise [SocketError] if point cannot be written

# File lib/wavefront-sdk/writers/proxy.rb, line 56
def _send_point(point)
  return if opts[:noop]

  conn.puts(point)
rescue StandardError
  raise Wavefront::Exception::SocketError
end
default_port() click to toggle source

return [Integer] the port to connect to, if none is supplied

# File lib/wavefront-sdk/writers/proxy.rb, line 66
def default_port
  2878
end
open_socket(proxy, port) click to toggle source
# File lib/wavefront-sdk/writers/proxy.rb, line 46
def open_socket(proxy, port)
  @conn = TCPSocket.new(proxy, port)
rescue StandardError => e
  logger.log(e, :error)
  raise Wavefront::Exception::InvalidEndpoint
end