Class: WavefrontCli::Query
- Includes:
- Wavefront::Mixins
- Defined in:
- lib/wavefront-cli/query.rb
Overview
CLI coverage for the v2 ‘query’ API.
Instance Attribute Summary
Attributes inherited from Base
#klass, #klass_word, #options, #wf
Instance Method Summary collapse
-
#default_granularity(window) ⇒ Object
Work out a sensible granularity based on the time window.
- #do_default ⇒ Object
- #do_raw ⇒ Object
- #extra_validation ⇒ Object
Methods inherited from Base
#check_status, #dispatch, #display, #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, #import_to_create, #initialize, #load_display_class, #load_file, #mk_creds, #mk_opts, #run, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method
Constructor Details
This class inherits a constructor from WavefrontCli::Base
Instance Method Details
#default_granularity(window) ⇒ Object
Work out a sensible granularity based on the time window
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/wavefront-cli/query.rb', line 47 def default_granularity(window) if window < 300 :s elsif window < 10800 :m elsif window < 259200 :h else :d end end |
#do_default ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wavefront-cli/query.rb', line 11 def do_default opts = { autoEvents: [:events], i: [:inclusive], summarization: [:summarize] || 'mean', listMode: true, strict: true, includeObsoleteMetrics: [:obsolete], sorted: true } [:start] = if [:start] parse_time([:start], true) else (Time.now - 600).to_i end if [:end] [:end] = parse_time([:end], true) t_end = [:end] else t_end = Time.now.to_i end [:granularity] ||= default_granularity((t_end - [:start]).to_i) opts[:n] = [:name] if [:name] opts[:p] = [:points] if [:points] wf.query([:'<query>'], [:granularity], [:start], [:end] || nil, opts) end |
#do_raw ⇒ Object
68 69 70 71 |
# File 'lib/wavefront-cli/query.rb', line 68 def do_raw wf.raw([:'<metric>'], [:host], [:start], [:end]) end |
#extra_validation ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/wavefront-cli/query.rb', line 59 def extra_validation return unless [:granularity] begin wf_granularity?([:granularity]) rescue Wavefront::Exception::InvalidGranularity abort "'#{[:granularity]}' is not a valid granularity." end end |