Class: RailsStat
- Inherits:
-
Object
- Object
- RailsStat
- Defined in:
- lib/analyzer_tools/rails_stat.rb
Overview
RailsStat displays a the current requests and lines logged per second. Default interval is 10 seconds.
Class Attribute Summary collapse
-
.lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Current status line.
-
#thread ⇒ Object
readonly
The log reading thread.
Class Method Summary collapse
-
.start(*args) ⇒ Object
RailsStat.start ‘online-43things.log’, ‘online-43people.log’, 10.
Instance Method Summary collapse
-
#initialize(io, interval, offset = 0) ⇒ RailsStat
constructor
Creates a new RailsStat that will listen on
io
and print everyinterval
seconds. - #print ⇒ Object
-
#start ⇒ Object
Starts the RailsStat running.
Constructor Details
#initialize(io, interval, offset = 0) ⇒ RailsStat
Creates a new RailsStat that will listen on io
and print every interval
seconds. offset
is only used for multi-file support.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/analyzer_tools/rails_stat.rb', line 64 def initialize(io, interval, offset = 0) @io = io @io_path = File.basename io.path rescue 'unknown' @interval = interval.to_f @offset = offset @mutex = Mutex.new @status = '' @last_len = 0 @lines = 0 @count = 0 @thread = nil end |
Class Attribute Details
.lines ⇒ Object (readonly)
Returns the value of attribute lines.
11 12 13 |
# File 'lib/analyzer_tools/rails_stat.rb', line 11 def lines @lines end |
Instance Attribute Details
#status ⇒ Object (readonly)
Current status line
58 59 60 |
# File 'lib/analyzer_tools/rails_stat.rb', line 58 def status @status end |
#thread ⇒ Object (readonly)
The log reading thread
53 54 55 |
# File 'lib/analyzer_tools/rails_stat.rb', line 53 def thread @thread end |
Class Method Details
.start(*args) ⇒ Object
RailsStat.start ‘online-43things.log’, ‘online-43people.log’, 10
Starts a new RailsStat for filenames
that prints every interval
seconds.
Stats for multiple log files requires curses.
22 23 24 25 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/analyzer_tools/rails_stat.rb', line 22 def self.start(*args) interval = 10 interval = Float(args.pop) if Float(args.last) rescue nil stats = [] if args.length > 1 and not defined? Curses then $stderr.puts "Multiple logfile support requires curses" exit 1 end if defined? Curses then Curses.init_screen Curses.clear Curses.addstr "Collecting data...\n" Curses.refresh @lines = [] end args.each_with_index do |filename, offset| stat = self.new File.open(filename), interval, offset stat.start stats << stat end stats.each { |stat| stat.thread.join } end |
Instance Method Details
#print ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/analyzer_tools/rails_stat.rb', line 90 def print if defined? Curses then Curses.setpos @offset, 0 Curses.addstr ' ' * @last_len Curses.setpos @offset, 0 Curses.addstr "#{@io_path}\t#{@status}" Curses.refresh else print "\r" print ' ' * @last_len print "\r" print @status $stdout.flush end end |
#start ⇒ Object
Starts the RailsStat running. This method never returns.
81 82 83 84 85 86 87 88 |
# File 'lib/analyzer_tools/rails_stat.rb', line 81 def start trap 'INT' do Curses.close_screen if defined? Curses exit end start_printer read_log end |