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
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_output ⇒ Object
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_output ⇒ Object
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
|
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
|