Class: Thin::Stats::Adapter
Class Thin::Stats::Adapter < Object
(in files lib/thin/stats.rb )Rack adapter to log stats about a Rack application.
Includes
- ERB::Util
Methods
Public Class new(app, path='/stats')
[ show source ]
# File lib/thin/stats.rb, line 9 9: def initialize(app, path='/stats') 10: @app = app 11: @path = path 12: 13: @template = ERB.new(File.read(File.dirname(__FILE__) + '/stats.html.erb')) 14: 15: @requests = 0 16: @requests_finished = 0 17: @start_time = Time.now 18: end
Public Instance call(env)
[ show source ]
# File lib/thin/stats.rb, line 20 20: def call(env) 21: if env['PATH_INFO'].index(@path) == 0 22: serve(env) 23: else 24: log(env) { @app.call(env) } 25: end 26: end
Public Instance log(env) {|| ...}
[ show source ]
# File lib/thin/stats.rb, line 28 28: def log(env) 29: @requests += 1 30: @last_request = Rack::Request.new(env) 31: request_started_at = Time.now 32: 33: response = yield 34: 35: @requests_finished += 1 36: @last_request_time = Time.now - request_started_at 37: 38: response 39: end
Public Instance serve(env)
[ show source ]
# File lib/thin/stats.rb, line 41 41: def serve(env) 42: body = @template.result(binding) 43: 44: [ 45: 200, 46: { 'Content-Type' => 'text/html' }, 47: [body] 48: ] 49: end