Class: Tailstrom::Command::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/tailstrom/command/stat.rb

Instance Method Summary collapse

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(options)
  @infile = options[:static_infile] || $stdin
  @counters = CounterCollection.new
  @options = { :async => !options[:static_infile] }.merge options
  @table = Table.new schema
end

Instance Method Details

#runObject



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

#schemaObject



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