Class: Ddtop::Ddtop
- Inherits:
-
Object
- Object
- Ddtop::Ddtop
- Defined in:
- lib/ddtop/ddtop.rb
Constant Summary collapse
- TOP_CMD =
'top -b'
- PREFIX =
'ddtop'
Instance Method Summary collapse
-
#initialize ⇒ Ddtop
constructor
A new instance of Ddtop.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Ddtop
Returns a new instance of Ddtop.
5 6 7 8 9 10 |
# File 'lib/ddtop/ddtop.rb', line 5 def initialize api_key = ENV['DD_API_KEY'] host = %x[hostname -f 2> /dev/null].strip host = Socket.gethostname if host.empty? @dog = Dogapi::Client.new(api_key, nil, host) end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ddtop/ddtop.rb', line 12 def run clear_screen emits = get_emits(ARGV) summary, fields = nil values = [] head_hook = proc do if summary and not values.empty? emit_points(summary, fields, values, emits) values.clear end end top_each_lien(head_hook) do |top, line| if head?(line) summary, fields = parse_header(top, line) elsif not line.empty? values << line.split(/\s+/, fields.length) end end end |