class WavefrontWavefrontOutput::Query

Display query results in Wavefront wire format. We have to handle raw and normal output in different ways.

Public Instance Methods

_run() click to toggle source
# File lib/wavefront-cli/output/wavefront/query.rb, line 12
def _run
  if options[:raw]
    raw_output
  else
    query_output
  end
end
query_output() click to toggle source
# File lib/wavefront-cli/output/wavefront/query.rb, line 32
def query_output
  check_query_response

  resp[:timeseries].each_with_object([]) do |ts, a|
    ts[:data].each do |point|
      a.<< wavefront_format(ts[:label],
                            point[1],
                            point[0],
                            ts[:host],
                            ts[:tags])
    end
  end.join("\n")
end
raw_output() click to toggle source
# File lib/wavefront-cli/output/wavefront/query.rb, line 20
def raw_output
  resp.each_with_object('') do |point, a|
    point[:points].each do |p|
      a.<< wavefront_format(options[:'<metric>'],
                            p[:value],
                            p[:timestamp],
                            options[:host],
                            point[:tags]) + "\n"
    end
  end
end
wavefront_format(path, value, timestamp, source, tags = nil) click to toggle source
# File lib/wavefront-cli/output/wavefront/query.rb, line 46
def wavefront_format(path, value, timestamp, source, tags = nil)
  arr = [path, value, timestamp, format('source=%<source>s',
                                        source: source)]
  arr.<< tags.to_wf_tag if tags && !tags.empty?
  arr.join(' ')
end