Class: Mongrel::StatisticsFilter

### Home Classes Methods

### In Files

- lib/mongrel/handlers.rb

### Parent

Mongrel::HttpHandler

### Methods

- ::new
- #dump
- #process

### Files

- CHANGELOG
- COPYING
- LICENSE
- README
- Makefile

### Class/Module Index

Quicksearch

- Mongrel
- Mongrel::CGIWrapper
- Mongrel::Camping
- Mongrel::Camping::CampingHandler
- Mongrel::Command
- Mongrel::Command::Base
- Mongrel::Command::Registry
- Mongrel::Configurator
- Mongrel::Const
- Mongrel::DeflateFilter
- Mongrel::DirHandler
- Mongrel::Error404Handler
- Mongrel::Gems
- Mongrel::HeaderOut
- Mongrel::HttpHandler
- Mongrel::HttpHandlerPlugin
- Mongrel::HttpParams
- Mongrel::HttpParser
- Mongrel::HttpParserError
- Mongrel::HttpRequest
- Mongrel::HttpResponse
- Mongrel::HttpServer
- Mongrel::Rails
- Mongrel::Rails::RailsConfigurator
- Mongrel::Rails::RailsHandler
- Mongrel::RedirectHandler
- Mongrel::StatisticsFilter
- Mongrel::Stats
- Mongrel::StatusHandler
- Mongrel::StopServer
- Mongrel::TimeoutError
- Mongrel::URIClassifier
- Mongrel::URIClassifier::RegistrationError
- Mongrel::URIClassifier::UsageError
- RequestLog
- RequestLog::Access
- RequestLog::Files
- RequestLog::Objects
- RequestLog::Params
- RequestLog::Threads
- IO
- Kernel
- MongrelDbg
- TCPServer

No matching classes.

# Mongrel::StatisticsFilter

Implements a few basic statistics for a particular URI. Register it anywhere you want in the request chain and it'll quickly gather some numbers for you to analyze. It is pretty fast, but don't put it out in production.

You should pass the filter to StatusHandler as StatusHandler.new(:stats_filter => stats). This lets you then hit the status URI you want and get these stats from a browser.

StatisticsFilter takes an option of :sample_rate. This is a number that's passed to rand and if that number gets hit then a sample is taken. This helps reduce the load and keeps the statistics valid (since sampling is a part of how they work).

The exception to :sample_rate is that inter-request time is sampled on every request. If this wasn't done then it wouldn't be accurate as a measure of time between requests.

### Attributes

stats[R]

### Public Class Methods

new(ops={}) click to toggle source

    # File lib/mongrel/handlers.rb, line 341
    def initialize(ops={})
      @sample_rate = ops[:sample_rate] || 300

      @processors = Mongrel::Stats.new("processors")
      @reqsize = Mongrel::Stats.new("request Kb")
      @headcount = Mongrel::Stats.new("req param count")
      @respsize = Mongrel::Stats.new("response Kb")
      @interreq = Mongrel::Stats.new("inter-request time")
    end

### Public Instance Methods

dump() click to toggle source

    # File lib/mongrel/handlers.rb, line 362
    def dump
      "#{@processors.to_s}\n#{@reqsize.to_s}\n#{@headcount.to_s}\n#{@respsize.to_s}\n#{@interreq.to_s}"
    end

process(request, response) click to toggle source

    # File lib/mongrel/handlers.rb, line 352
    def process(request, response)
      if rand(@sample_rate)+1 == @sample_rate
        @processors.sample(listener.workers.list.length)
        @headcount.sample(request.params.length)
        @reqsize.sample(request.body.length / 1024.0)
        @respsize.sample((response.body.length + response.header.out.length) / 1024.0)
      end
      @interreq.tick
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.