Class: WavefrontCli::Query

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#check_status, #dispatch, #display, #do_delete, #do_describe, #do_import, #do_list, #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



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wavefront-cli/query.rb', line 48

def default_granularity(window)
  if window < 300
    :s
  elsif window < 10800
    :m
  elsif window < 259200
    :h
  else
    :d
  end
end

#do_defaultObject



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:             options[:events],
    i:                      options[:inclusive],
    summarization:          options[:summarize] || 'mean',
    listMode:               true,
    strict:                 true,
    includeObsoleteMetrics: options[:obsolete],
    sorted:                 true
  }

  if options[:start]
    options[:start] = parse_time(options[:start], true)
  else
    options[:start] = (Time.now - 600).to_i
  end

  if options[:end]
    options[:end] = parse_time(options[:end], true)
    t_end = options[:end]
  else
    t_end = Time.now.to_i
  end

  options[:granularity] ||= default_granularity((t_end -
                                                options[:start]).to_i)

  opts[:n] = options[:name] if options[:name]
  opts[:p] = options[:points] if options[:points]

  wf.query(options[:'<query>'], options[:granularity],
           options[:start], options[:end] || nil, opts)
end

#do_rawObject



69
70
71
72
# File 'lib/wavefront-cli/query.rb', line 69

def do_raw
  wf.raw(options[:'<metric>'], options[:host], options[:start],
         options[:end])
end

#extra_validationObject



60
61
62
63
64
65
66
67
# File 'lib/wavefront-cli/query.rb', line 60

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