class 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
Public Class Methods
# 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
# 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
# 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