Class: WavefrontWavefrontOutput::Query

Inherits:
WavefrontCsvOutput::Base show all
Defined in:
lib/wavefront-cli/output/wavefront/query.rb

Overview

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

Instance Attribute Summary

Attributes inherited from WavefrontCsvOutput::Base

#options, #resp

Instance Method Summary collapse

Methods inherited from WavefrontCsvOutput::Base

#check_query_response, #initialize, #run

Constructor Details

This class inherits a constructor from WavefrontCsvOutput::Base

Instance Method Details

#_runObject



12
13
14
15
16
17
18
# File 'lib/wavefront-cli/output/wavefront/query.rb', line 12

def _run
  if options[:raw]
    raw_output
  else
    query_output
  end
end

#query_outputObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# 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_outputObject



20
21
22
23
24
25
26
27
28
29
30
# 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) ⇒ Object



46
47
48
49
50
51
# 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