class Rack::Stats::Runtime

Public Class Methods

new(statsd, app, env, stats, namespace) click to toggle source
# File lib/rack/stats/runtime.rb, line 9
def initialize(statsd, app, env, stats, namespace)
  @batch = Statsd::Batch.new statsd
  @app, @env, @timer = app, env, Timer.new
  @stats = stats.map do |stat|
    klass = stat[:type] == :increment ? Stat::Increment : Stat::Timing
    klass.new stat[:name], stat[:value], stat[:condition], namespace
  end
end

Public Instance Methods

execute() click to toggle source
# File lib/rack/stats/runtime.rb, line 18
def execute
  r = @timer.time { @app.call(@env) }
  flush_data @timer.duration, Rack::Response.new(r.last, r.first, r[1])
  r
end
flush_data(duration, response) click to toggle source
# File lib/rack/stats/runtime.rb, line 24
def flush_data(duration, response)
  @stats.each do |stat|
    stat.execute @batch, Rack::Request.new(@env), duration, response
  end

  @batch.flush
end