Class: Wavefront::Writer::Socket

Inherits:
Core
  • Object
show all
Defined in:
lib/wavefront-sdk/writers/socket.rb

Overview

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.)

Instance Attribute Summary

Attributes inherited from Core

#calling_class, #conn, #creds, #logger, #opts, #summary

Instance Method Summary collapse

Methods inherited from Core

#hash_to_wf, #initialize, #prefix_points, #respond, #screen_points, #send_point, #valid_point?, #write

Methods included from Validators

#wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_ts?, #wf_user_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::Writer::Core

Instance Method Details

#closeObject

Close the connection described by the @conn instance variable.



36
37
38
39
40
41
# File 'lib/wavefront-sdk/writers/socket.rb', line 36

def close
  return if opts[:noop]

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

#openTCPSocket

Open a socket to a Wavefront proxy, putting the descriptor in instance variable @conn. rubocop:disable Metrics/AbcSize

Returns:

  • (TCPSocket)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wavefront-sdk/writers/socket.rb', line 16

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)

  begin
    @conn = TCPSocket.new(creds[:proxy], port)
  rescue StandardError => e
    logger.log(e, :error)
    raise Wavefront::Exception::InvalidEndpoint
  end
end

#validate_credentials(creds) ⇒ Object



43
44
45
46
47
48
# File 'lib/wavefront-sdk/writers/socket.rb', line 43

def validate_credentials(creds)
  return true if creds.key?(:proxy)

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