Class: WavefrontWavefrontOutput::Query
Overview
Display query results in Wavefront wire format. We have to handle raw and normal output in different ways.
Instance Attribute Summary
#options, #resp
Instance Method Summary
collapse
#check_query_response, #initialize, #run
Instance Method Details
#_run ⇒ Object
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_output ⇒ Object
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_output ⇒ Object
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
|
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
|