Class: Tailstrom::Command::Stat
- Inherits:
-
Object
- Object
- Tailstrom::Command::Stat
- Defined in:
- lib/tailstrom/command/stat.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Stat
constructor
A new instance of Stat.
- #run ⇒ Object
- #schema ⇒ Object
Constructor Details
#initialize(options) ⇒ Stat
Returns a new instance of Stat.
8 9 10 11 12 13 |
# File 'lib/tailstrom/command/stat.rb', line 8 def initialize() @infile = [:static_infile] || $stdin @counters = CounterCollection.new @options = { :async => ![:static_infile] }.merge @table = Table.new schema end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tailstrom/command/stat.rb', line 26 def run reader = TailReader.new @infile, @options reader.each_line do |line| @counters[line[:key]] << line[:value] end height = terminal_height i = 0 begin sleep @options[:interval] if i % height == 0 @table.print_header end print_counters @counters.clear i = i + 1 end while !reader.eof? rescue Interrupt exit 0 end |
#schema ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tailstrom/command/stat.rb', line 15 def schema [ ({ :name => 'time', :width => 8 } if @options[:async]), { :name => 'count', :width => 7 }, { :name => 'min', :width => 10 }, { :name => 'max', :width => 10 }, { :name => 'avg', :width => 10 }, { :name => 'key', :width => 10, :align => :left } ].compact end |