Class: ScoutStatsdRack::Middleware
- Inherits:
-
Object
- Object
- ScoutStatsdRack::Middleware
- Defined in:
- lib/scout_statsd_rack.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call_with_timing(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #statsd ⇒ Object
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
16 17 18 |
# File 'lib/scout_statsd_rack.rb', line 16 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
14 15 16 |
# File 'lib/scout_statsd_rack.rb', line 14 def app @app end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/scout_statsd_rack.rb', line 20 def call(env) (status, headers, body), response_time = call_with_timing(env) statsd.timing("rack.response", response_time) statsd.increment("rack.response_codes.#{status.to_s.gsub(/\d{2}$/,'xx')}") # Rack response [status, headers, body] rescue Exception => exception statsd.increment("rack.response_codes.5xx") raise end |
#call_with_timing(env) ⇒ Object
31 32 33 34 35 |
# File 'lib/scout_statsd_rack.rb', line 31 def call_with_timing(env) start = Time.now result = @app.call(env) [result, ((Time.now - start) * 1000).round] end |
#statsd ⇒ Object
37 38 39 |
# File 'lib/scout_statsd_rack.rb', line 37 def statsd ScoutStatsdRack.statsd end |