Class: Rhoconnect::Middleware::Stats
- Inherits:
-
Object
- Object
- Rhoconnect::Middleware::Stats
- Defined in:
- lib/rhoconnect/middleware/stats.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Stats
constructor
A new instance of Stats.
Constructor Details
#initialize(app) ⇒ Stats
Returns a new instance of Stats.
6 7 8 |
# File 'lib/rhoconnect/middleware/stats.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rhoconnect/middleware/stats.rb', line 10 def call(env) if Rhoconnect.stats || Rhoconnect::Server.stats start = Time.now.to_f status, headers, body = @app.call(env) finish = Time.now.to_f metric = "http:#{env['REQUEST_METHOD']}:#{env['PATH_INFO']}" source_name = env['rack.request.query_hash']["source_name"] if env['rack.request.query_hash'] metric << ":#{source_name}" if source_name Rhoconnect::Stats::Record.save_average(metric,finish - start) [status, headers, body] else status, headers, body = @app.call(env) [status, headers, body] end end |