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



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

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

#query_outputObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wavefront-cli/output/wavefront/query.rb', line 30

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]) + "\n"
    end
  end
end

#raw_outputObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wavefront-cli/output/wavefront/query.rb', line 18

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



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

def wavefront_format(path, value, timestamp, source, tags = nil)
  arr = [path, value, timestamp, format('source=%s', source)]
  arr.<< tags.to_wf_tag if tags && !tags.empty?
  arr.join(' ')
end