class WavefrontCli::Query
CLI coverage for the v2 'query' API.
Attributes
query_string[R]
Public Instance Methods
all_aliases()
click to toggle source
@return [Hash] all query aliases for the active profile
# File lib/wavefront-cli/query.rb, line 123 def all_aliases WavefrontCli::OptHandler.new(options).opts.select do |line| line.to_s.start_with?('q_') end end
basic_q_opts()
click to toggle source
Every query gets these options. They're modified by q_opts
# File lib/wavefront-cli/query.rb, line 65 def basic_q_opts { autoEvents: options[:events], i: options[:inclusive], summarization: options[:summarize] || 'mean', listMode: true, strict: !options[:nostrict], includeObsoleteMetrics: options[:obsolete], sorted: true } end
default_granularity(window)
click to toggle source
Work out a sensible granularity based on the time window
# File lib/wavefront-cli/query.rb, line 97 def default_granularity(window) window = window.abs / 1000 if window < 300 :s elsif window < 10_800 :m elsif window < 259_200 :h else :d end end
do_aliases()
click to toggle source
# File lib/wavefront-cli/query.rb, line 48 def do_aliases all_aliases end
do_default()
click to toggle source
# File lib/wavefront-cli/query.rb, line 19 def do_default qs = query_string || options[:'<query>'] t_start = window_start t_end = window_end granularity = granularity(t_start, t_end) t_end = nil unless options[:end] wf.query(qs, granularity, t_start, t_end, q_opts) end
do_raw()
click to toggle source
# File lib/wavefront-cli/query.rb, line 30 def do_raw wf.raw(options[:'<metric>'], options[:host], options[:start], options[:end]) end
do_run()
click to toggle source
# File lib/wavefront-cli/query.rb, line 35 def do_run alias_key = format('q_%<alias>s', alias: options[:'<alias>']).to_sym query = all_aliases.fetch(alias_key, nil) unless query abort "Query not found. 'wf query aliases' will show all " \ 'aliased queries.' end @query_string = query do_default end
extra_validation()
click to toggle source
# File lib/wavefront-cli/query.rb, line 111 def extra_validation return unless options[:granularity] begin wf_granularity?(options[:granularity]) rescue Wavefront::Exception::InvalidGranularity abort "'#{options[:granularity]}' is not a valid granularity." end end
granularity(t_start, t_end)
click to toggle source
# File lib/wavefront-cli/query.rb, line 91 def granularity(t_start, t_end) options[:granularity] || default_granularity(t_start - t_end) end
handle_errcode404(_status)
click to toggle source
# File lib/wavefront-cli/query.rb, line 129 def handle_errcode404(_status) 'Perhaps metric does not exist for given host.' end
no_api_response()
click to toggle source
# File lib/wavefront-cli/query.rb, line 15 def no_api_response %w[do_aliases] end
q_opts()
click to toggle source
@return [Hash] options for the SDK query method
# File lib/wavefront-cli/query.rb, line 54 def q_opts basic_q_opts.tap do |o| o[:n] = options[:name] o[:p] = options[:points] o[:view] = 'HISTOGRAM' if options[:histogramview] o[:cached] = false if options[:nocache] end.compact end
window_end()
click to toggle source
@return [Integer] end of query window. If one has been
given, that; if not, now
# File lib/wavefront-cli/query.rb, line 86 def window_end t = options[:end] ? options[:end].dup : Time.now parse_time(t, true) end
window_start()
click to toggle source
@return [Integer] start of query window. If one has been
given, that; if not, ten minutes ago
# File lib/wavefront-cli/query.rb, line 78 def window_start t = options[:start] ? options[:start].dup : Time.now - 600 parse_time(t, true) end