Class: Wavefront::Write
- Defined in:
- lib/wavefront-sdk/write.rb
Overview
This class helps you send points to a Wavefront proxy in native format. Usually this is done on port 2878.
The points are prepped in the BaseWrite class, which this extends. This class provides the transport mechanism.
Instance Attribute Summary
Attributes inherited from BaseWrite
Attributes inherited from Base
#conn, #debug, #logger, #net, #noop, #opts, #update_keys, #verbose
Instance Method Summary collapse
-
#close ⇒ Object
Close the socket described by the @sock instance variable.
-
#open ⇒ Object
Open a socket to a Wavefront proxy, putting the descriptor in instance variable @sock.
-
#raw(points, openclose = true) ⇒ Object
Send raw data to a Wavefront proxy, automatically opening and closing a socket.
- #really_send_point(point) ⇒ Object
-
#setup_endpoint(creds) ⇒ Object
Overload the method which sets an API endpoint.
Methods inherited from BaseWrite
#hash_to_wf, #paths_to_deltas, #post_initialize, #prepped_points, #send_point, #setup_options, #summary_string, #valid_point?, #write, #write_delta
Methods inherited from Base
#api_base, #api_delete, #api_get, #api_path, #api_post, #api_put, #everything, #hash_for_update, #initialize, #log, #mk_conn, #print_message, #respond, #time_to_ms
Methods included from Mixins
#parse_relative_time, #parse_time, #relative_time, #time_multiplier
Methods included from Validators
#wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #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::Base
Instance Method Details
#close ⇒ Object
Close the socket described by the @sock instance variable.
49 50 51 52 53 |
# File 'lib/wavefront-sdk/write.rb', line 49 def close return if opts[:noop] log('Closing connection to proxy.', :info) sock.close end |
#open ⇒ Object
Open a socket to a Wavefront proxy, putting the descriptor in instance variable @sock.
rubocop:disable Metrics/MethodLength
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wavefront-sdk/write.rb', line 30 def open if opts[:noop] log('No-op requested. Not opening connection to proxy.') return true end port = net[:port] || 2878 log("Connecting to #{net[:proxy]}:#{port}.", :info) begin @sock = TCPSocket.new(net[:proxy], port) rescue StandardError => e log(e, :error) raise Wavefront::Exception::InvalidEndpoint end end |
#raw(points, openclose = true) ⇒ Object
Send raw data to a Wavefront proxy, automatically opening and closing a socket.
74 75 76 77 78 79 80 81 82 |
# File 'lib/wavefront-sdk/write.rb', line 74 def raw(points, openclose = true) open if openclose begin [points].flatten.each { |p| send_point(p) } ensure close if openclose end end |
#really_send_point(point) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wavefront-sdk/write.rb', line 12 def really_send_point(point) begin sock.puts(point) rescue StandardError => e summary[:unsent] += 1 log('WARNING: failed to send point.') log(e.to_s, :debug) return false end summary[:sent] += 1 true end |
#setup_endpoint(creds) ⇒ Object
Overload the method which sets an API endpoint. A proxy endpoint has an address and a port, rather than an address and a token.
59 60 61 |
# File 'lib/wavefront-sdk/write.rb', line 59 def setup_endpoint(creds) @net = creds end |