Class: Napa::Middleware::RequestStats
- Inherits:
-
Object
- Object
- Napa::Middleware::RequestStats
- Defined in:
- lib/napa/middleware/request_stats.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RequestStats
constructor
A new instance of RequestStats.
Constructor Details
#initialize(app) ⇒ RequestStats
Returns a new instance of RequestStats.
4 5 6 |
# File 'lib/napa/middleware/request_stats.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/napa/middleware/request_stats.rb', line 8 def call(env) # Mark the request time start = Time.now # Process the request status, headers, body = @app.call(env) # Mark the response time stop = Time.now # Calculate total response time response_time = stop - start # Emit stats to StatsD Napa::Stats.emitter.increment('api_requests') Napa::Stats.emitter.timing('api_response_time', response_time) # Return the results [status, headers, body] end |