Class: Thin::Stats::Adapter

### Home Classes Methods

### In Files

- lib/thin/stats.rb

### Parent

Object

### Methods

- ::new
- #call
- #log
- #serve

### Included Modules

- ERB::Util

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Thin::Stats::Adapter

Rack adapter to log stats about a Rack application.

### Public Class Methods

new(app, path='/stats') click to toggle source

    # File lib/thin/stats.rb, line 9
    def initialize(app, path='/stats')
      @app  = app
      @path = path

      @template = ERB.new(File.read(File.dirname(__FILE__) + '/stats.html.erb'))

      @requests          = 0
      @requests_finished = 0
      @start_time        = Time.now
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/thin/stats.rb, line 20
    def call(env)
      if env['PATH_INFO'].index(@path) == 0
        serve(env)
      else
        log(env) { @app.call(env) }
      end
    end

log(env) click to toggle source

    # File lib/thin/stats.rb, line 28
    def log(env)
      @requests += 1
      @last_request = Rack::Request.new(env)
      request_started_at = Time.now

      response = yield

      @requests_finished += 1
      @last_request_time = Time.now - request_started_at

      response
    end

serve(env) click to toggle source

    # File lib/thin/stats.rb, line 41
    def serve(env)
      body = @template.result(binding)

      [
        200,
        { 'Content-Type' => 'text/html' },
        [body]
      ]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.