Class | Mongrel::StatisticsFilter |
In: |
lib/mongrel/handlers.rb
lib/mongrel/handlers.rb |
Parent: | HttpHandler |
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.
stats | [R] | |
stats | [R] |
# File lib/mongrel/handlers.rb, line 341 341: def initialize(ops={}) 342: @sample_rate = ops[:sample_rate] || 300 343: 344: @processors = Mongrel::Stats.new("processors") 345: @reqsize = Mongrel::Stats.new("request Kb") 346: @headcount = Mongrel::Stats.new("req param count") 347: @respsize = Mongrel::Stats.new("response Kb") 348: @interreq = Mongrel::Stats.new("inter-request time") 349: end
# File lib/mongrel/handlers.rb, line 341 341: def initialize(ops={}) 342: @sample_rate = ops[:sample_rate] || 300 343: 344: @processors = Mongrel::Stats.new("processors") 345: @reqsize = Mongrel::Stats.new("request Kb") 346: @headcount = Mongrel::Stats.new("req param count") 347: @respsize = Mongrel::Stats.new("response Kb") 348: @interreq = Mongrel::Stats.new("inter-request time") 349: end
# File lib/mongrel/handlers.rb, line 362 362: def dump 363: "#{@processors.to_s}\n#{@reqsize.to_s}\n#{@headcount.to_s}\n#{@respsize.to_s}\n#{@interreq.to_s}" 364: end
# File lib/mongrel/handlers.rb, line 362 362: def dump 363: "#{@processors.to_s}\n#{@reqsize.to_s}\n#{@headcount.to_s}\n#{@respsize.to_s}\n#{@interreq.to_s}" 364: end
# File lib/mongrel/handlers.rb, line 352 352: def process(request, response) 353: if rand(@sample_rate)+1 == @sample_rate 354: @processors.sample(listener.workers.list.length) 355: @headcount.sample(request.params.length) 356: @reqsize.sample(request.body.length / 1024.0) 357: @respsize.sample((response.body.length + response.header.out.length) / 1024.0) 358: end 359: @interreq.tick 360: end
# File lib/mongrel/handlers.rb, line 352 352: def process(request, response) 353: if rand(@sample_rate)+1 == @sample_rate 354: @processors.sample(listener.workers.list.length) 355: @headcount.sample(request.params.length) 356: @reqsize.sample(request.body.length / 1024.0) 357: @respsize.sample((response.body.length + response.header.out.length) / 1024.0) 358: end 359: @interreq.tick 360: end