Class: WavefrontCli::Write
- Defined in:
- lib/wavefront-cli/write.rb
Overview
Send points via a proxy. This inherits from the same base class as Report, but has to do a couple of things differently, as it speaks to a proxy rather than to the API.
Constant Summary
Constants included from Constants
Constants::ALL_PAGE_SIZE, Constants::DEFAULT_OPTS, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS
Instance Attribute Summary
Attributes inherited from BaseWrite
Attributes inherited from Base
#klass, #klass_word, #options, #wf
Instance Method Summary collapse
-
#_sdk_class ⇒ Object
I chose to prioritise UI consistency over internal elegance here.
- #close_connection ⇒ Object
- #default_port ⇒ Object
- #distribution? ⇒ Boolean
-
#do_distribution ⇒ Object
rubocop:disable Metrics/AbcSize.
- #extra_options ⇒ Object
- #mk_creds ⇒ Object
-
#mk_dist ⇒ Object
Turn our user’s representation of a distribution into one which suits Wavefront.
- #open_connection ⇒ Object
- #validate_opts ⇒ Object
- #validate_opts_file ⇒ Object
Methods inherited from BaseWrite
#call_write, #do_file, #do_point, #enough_fields?, #expand_dist, #extract_path, #extract_source, #extract_tags, #extract_ts, #extract_value, #line_tags, #process_input, #process_input_file, #process_line, #read_stdin, #send_point, #tags_to_hash, #valid_format?, #valid_timestamp?
Methods inherited from Base
#check_status, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_delete, #do_describe, #do_import, #do_list, #do_search, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_set, #do_tags, #do_undelete, #do_update, #format_var, #handle_error, #handle_response, #hcl_fields, #import_to_create, #initialize, #load_display_class, #load_file, #load_from_stdin, #mk_opts, #no_api_response, #ok_exit, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #validate_id, #validate_input, #validate_tags, #validator_exception, #validator_method
Constructor Details
This class inherits a constructor from WavefrontCli::Base
Instance Method Details
#_sdk_class ⇒ Object
I chose to prioritise UI consistency over internal elegance here. The write command doesn’t follow the age-old assumption that each command maps 1:1 to a similarly named SDK class. Write can use write or distribution.
40 41 42 43 |
# File 'lib/wavefront-cli/write.rb', line 40 def _sdk_class return 'Wavefront::Distribution' if distribution? 'Wavefront::Write' end |
#close_connection ⇒ Object
86 87 88 |
# File 'lib/wavefront-cli/write.rb', line 86 def close_connection wf.close end |
#default_port ⇒ Object
58 59 60 |
# File 'lib/wavefront-cli/write.rb', line 58 def default_port distribution? ? 40000 : 2878 end |
#distribution? ⇒ Boolean
45 46 47 48 |
# File 'lib/wavefront-cli/write.rb', line 45 def distribution? return true if [:distribution] [:infileformat] && [:infileformat].include?('d') end |
#do_distribution ⇒ Object
rubocop:disable Metrics/AbcSize
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wavefront-cli/write.rb', line 11 def do_distribution p = { path: [:'<metric>'], interval: [:interval] || 'M', value: mk_dist, tags: ([:tag]) } p[:source] = [:host] if [:host] p[:ts] = parse_time([:time]) if [:time] send_point(p) end |
#extra_options ⇒ Object
31 32 33 |
# File 'lib/wavefront-cli/write.rb', line 31 def [:using] ? { writer: [:using] } : {} end |
#mk_creds ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/wavefront-cli/write.rb', line 50 def mk_creds { proxy: [:proxy], port: [:port] || default_port, socket: [:socket], endpoint: [:endpoint], token: [:token] } end |
#mk_dist ⇒ Object
Turn our user’s representation of a distribution into one which suits Wavefront. The SDK can do this for us.
26 27 28 29 |
# File 'lib/wavefront-cli/write.rb', line 26 def mk_dist xpanded = ([:'<val>']) wf.mk_distribution(xpanded.map(&:to_f)) end |
#open_connection ⇒ Object
82 83 84 |
# File 'lib/wavefront-cli/write.rb', line 82 def open_connection wf.open end |
#validate_opts ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wavefront-cli/write.rb', line 62 def validate_opts validate_opts_file if [:file] if [:using] == 'unix' return true if [:socket] raise(WavefrontCli::Exception::CredentialError, 'No socket path.') end return true if [:proxy] raise(WavefrontCli::Exception::CredentialError, 'No proxy address.') end |
#validate_opts_file ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/wavefront-cli/write.rb', line 74 def validate_opts_file unless [:metric] || (.key?(:infileformat) && [:infileformat].include?('m')) raise(WavefrontCli::Exception::InsufficientData, "Supply a metric path in the file or with '-m'.") end end |