Class: WavefrontDisplay::Metric

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-cli/display/metric.rb

Overview

Format human-readable output for metrics.

Constant Summary

Constants included from WavefrontCli::Constants

WavefrontCli::Constants::ALL_PAGE_SIZE, WavefrontCli::Constants::DEFAULT_CONFIG, WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::EVENT_STATE_DIR, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS, WavefrontCli::Constants::SEARCH_SPLIT

Instance Attribute Summary

Attributes inherited from Base

#data, #options, #raw

Instance Method Summary collapse

Methods inherited from Base

#_prioritize_keys, #display_brief_freetext_results, #do_delete, #do_import, #do_list, #do_list_brief, #do_list_fields, #do_queries, #do_search, #do_search_brief, #do_search_fields, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #filter_data, #filter_fields_as_arr, #freetext_keys, #friendly_name, #human_time, #index_of_final_item, #initialize, #key_width, #long_output, #multicolumn, #pagination_line, #prioritize_keys, #priority_keys, #quoted, #readable_time, #readable_time_arr, #run, #run_error, #run_list, #run_search, #search_display_keys, #search_identifier_key, #time_formats

Constructor Details

This class inherits a constructor from WavefrontDisplay::Base

Instance Method Details

#bail_outObject



34
35
36
37
# File 'lib/wavefront-cli/display/metric.rb', line 34

def bail_out
  puts "Did not find metric '#{options[:'<metric>']}'."
  exit
end

#do_describeObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wavefront-cli/display/metric.rb', line 10

def do_describe
  bail_out if no_data?

  @data = data['hosts'].map do |h, _aggr|
    { host: h[:host], last_update: human_time(h[:last_update]) }
  end

  @data.sort_by { |h| h[:last_update] }.reverse

  multicolumn(:host, :last_update)
end

#do_list_underObject Also known as: do_list_all



22
23
24
25
26
# File 'lib/wavefront-cli/display/metric.rb', line 22

def do_list_under
  bail_out if data.empty?

  puts data.sort
end

#no_data?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/wavefront-cli/display/metric.rb', line 30

def no_data?
  data.empty? || data.hosts.empty?
end