Class: Salestation::Web::StatsdMiddleware
- Inherits:
-
Object
- Object
- Salestation::Web::StatsdMiddleware
- Defined in:
- lib/salestation/web/statsd_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, statsd, metric:) ⇒ StatsdMiddleware
constructor
A new instance of StatsdMiddleware.
Constructor Details
#initialize(app, statsd, metric:) ⇒ StatsdMiddleware
Returns a new instance of StatsdMiddleware.
5 6 7 8 9 |
# File 'lib/salestation/web/statsd_middleware.rb', line 5 def initialize(app, statsd, metric:) @app = app @statsd = statsd @metric = metric end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/salestation/web/statsd_middleware.rb', line 11 def call(env) start = Time.now status, header, body = @app.call env method = env['REQUEST_METHOD'] path = if route = env['sinatra.route'] route.split(' ').last else 'unknown-route' end @statsd.timing(@metric, (Time.now - start) * 1000, tags: [ "path:#{ path }", "method:#{ method }", "status:#{ status }" ]) [status, header, body] end |