Class: Wavefront::Cli::Ts

Inherits:
Wavefront::Cli show all
Includes:
Mixins
Defined in:
lib/wavefront/cli/ts.rb

Instance Attribute Summary collapse

Attributes inherited from Wavefront::Cli

#noop

Instance Method Summary collapse

Methods included from Mixins

#call_delete, #call_get, #call_post, #hash_to_qs, #interpolate_schema, #load_file, #parse_time, #time_to_ms, #uri_concat

Methods inherited from Wavefront::Cli

#initialize, #validate_opts

Constructor Details

This class inherits a constructor from Wavefront::Cli

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



24
25
26
# File 'lib/wavefront/cli/ts.rb', line 24

def arguments
  @arguments
end

#optionsObject

Returns the value of attribute options.



24
25
26
# File 'lib/wavefront/cli/ts.rb', line 24

def options
  @options
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wavefront/cli/ts.rb', line 26

def run
  raise 'Please supply a query.' if @arguments.empty?
  query = @arguments[0]

  if @options[:minutes]
    granularity = 'm'
  elsif @options[:hours]
    granularity = 'h'
  elsif @options[:seconds]
    granularity = 's'
  elsif @options[:days]
    granularity = 'd'
  else
    raise "You must specify a granularity of either --seconds, --minutes --hours or --days. See --help for more information."
  end

  unless Wavefront::Client::FORMATS.include?(@options[:format].to_sym)
    raise "The output format must be one of: #{Wavefront::Client::FORMATS.join(', ')}."
  end

  options = Hash.new
  options[:response_format] = @options[:format].to_sym
  options[:prefix_length] = @options[:prefixlength].to_i

  if @options[:start]
    options[:start_time] = Time.at(parse_time(@options[:start]))
  end

  if @options[:end]
    options[:end_time] = Time.at(parse_time(@options[:end]))
  end

  wave = Wavefront::Client.new(@options[:token], @options[:endpoint], @options[:debug], { noop: @options[:noop], verbose: @options[:verbose]})

  if noop
    wave.query(query, granularity, options)
    return
  end

  case options[:response_format]
  when :json
    pp wave.query(query, granularity, options)
  when :raw
    puts wave.query(query, granularity, options)
  when :graphite
    puts wave.query(query, granularity, options).graphite.to_json
  when :human
    puts wave.query(query, granularity, options).human
  else
    pp wave.query(query, granularity, options)
  end

  exit 0
end