Class: WavefrontDisplay::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-cli/display/query.rb

Overview

Format human-readable output for queries.

Constant Summary

Constants included from WavefrontCli::Constants

WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS

Instance Attribute Summary

Attributes inherited from Base

#data, #options, #raw

Instance Method Summary collapse

Methods inherited from Base

#do_delete, #do_import, #do_list, #do_list_brief, #do_search, #do_search_brief, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #friendly_name, #human_time, #initialize, #key_width, #long_output, #multicolumn, #pagination_line, #put_id_first, #readable_time, #readable_time_arr, #run, #run_error, #run_list, #run_search

Constructor Details

This class inherits a constructor from WavefrontDisplay::Base

Instance Method Details

#do_aliasesObject



53
54
55
56
57
58
59
# File 'lib/wavefront-cli/display/query.rb', line 53

def do_aliases
  if data.empty?
    puts 'No aliases defined.'
  else
    data.each { |k, _v| puts k.to_s[2..-1] }
  end
end

#do_defaultObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wavefront-cli/display/query.rb', line 9

def do_default
  d_obj = { name:       data.name,
            query:      data.query,
            timeseries: mk_timeseries(data),
            events:     mk_events(data) }

  if data.key?(:warnings) && !options[:nowarn]
    d_obj[:warnings] = data[:warnings]
  end

  @data = d_obj
  long_output
end

#do_rawObject



45
46
47
# File 'lib/wavefront-cli/display/query.rb', line 45

def do_raw
  data.each { |ts| puts humanize_series(ts[:points]).join("\n") }
end

#do_raw_404Object



49
50
51
# File 'lib/wavefront-cli/display/query.rb', line 49

def do_raw_404
  puts 'API 404: metric does not exist.'
end

#do_runObject



41
42
43
# File 'lib/wavefront-cli/display/query.rb', line 41

def do_run
  do_default
end

#mk_events(data) ⇒ Object



36
37
38
39
# File 'lib/wavefront-cli/display/query.rb', line 36

def mk_events(data)
  return [] unless data.key?(:events)
  data[:events].map { |s| humanize_event(s) }
end

#mk_timeseries(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wavefront-cli/display/query.rb', line 23

def mk_timeseries(data)
  return []  unless data.key?(:timeseries)

  data[:timeseries].each do |s|
    unless options[:nospark]
      s[:sparkline] = WavefrontSparkline.new(s[:data]).sparkline
      s.reorder!({label: nil, sparkline: nil})
    end

    s[:data] = humanize_series(s[:data])
  end
end