Class: Rack::Stats::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/stats/runtime.rb

Instance Method Summary collapse

Constructor Details

#initialize(statsd, app, env, stats) ⇒ Runtime

Returns a new instance of Runtime.



9
10
11
12
13
14
15
16
# File 'lib/rack/stats/runtime.rb', line 9

def initialize(statsd, app, env, stats)
  @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]
  end
end

Instance Method Details

#executeObject



18
19
20
21
22
# 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) ⇒ Object



24
25
26
27
28
29
30
# 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