Class: WavefrontDisplay::Query
- Inherits:
-
Base
- Object
- Base
- WavefrontDisplay::Query
show all
- Defined in:
- lib/wavefront-cli/display/query.rb
Overview
Format human-readable output for queries.
Constant Summary
WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS
Instance Attribute Summary
Attributes inherited from Base
#data, #options
Instance Method Summary
collapse
Methods inherited from Base
#do_delete, #do_import, #do_list, #do_list_brief, #do_search, #do_search_brief, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #friendly_name, #human_time, #initialize, #key_width, #long_output, #multicolumn, #put_id_first, #readable_time, #run, #run_error, #run_list, #run_search
Instance Method Details
#do_default ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/wavefront-cli/display/query.rb', line 8
def do_default
ts = if data.key?(:timeseries)
data[:timeseries].each do |s|
s[:data] = humanize_series(s[:data])
end
else
[]
end
events = if data.key?(:events)
data[:events].map { |s| humanize_event(s) }
else
[]
end
new = {
name: data.name,
query: data.query,
timeseries: ts,
events: events
}
@data = new
long_output
end
|
#do_raw ⇒ Object
34
35
36
|
# File 'lib/wavefront-cli/display/query.rb', line 34
def do_raw
data.each { |ts| puts humanize_series(ts[:points]).join("\n") }
end
|
#do_raw_404 ⇒ Object
38
39
40
|
# File 'lib/wavefront-cli/display/query.rb', line 38
def do_raw_404
puts 'API 404: metric does not exist.'
end
|
#humanize_event(data) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/wavefront-cli/display/query.rb', line 42
def humanize_event(data)
data[:start] = human_time(data[:start])
data[:end] = human_time(data[:end]) if data[:end]
data.delete(:isEphemeral)
data
end
|
#humanize_series(data) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/wavefront-cli/display/query.rb', line 49
def humanize_series(data)
last_date = nil
data.map! do |row|
if row.is_a?(Hash)
ht = human_time(row[:timestamp])
val = row[:value]
else
ht = human_time(row[0])
val = row[1]
end
date, time = ht.split
ds = date == last_date ? '' : date
last_date = date
format('%-12s %s %s', ds, time, val)
end
end
|