Class: UnicornMetrics::Middleware

Inherits:
Raindrops::Middleware
  • Object
show all
Defined in:
lib/unicorn_metrics/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • opts (Hash) (defaults to: {})

    options hash

Options Hash (opts):

  • :metrics (String)

    the HTTP endpoint that exposes the application metrics



11
12
13
14
15
# File 'lib/unicorn_metrics/middleware.rb', line 11

def initialize(app, opts = {})
  @registry     = UnicornMetrics::Registry
  @metrics_path = opts[:metrics] || "/metrics"
  super
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/unicorn_metrics/middleware.rb', line 17

def call(env)
  return metrics_response if env['PATH_INFO'] == @metrics_path

  response = nil
  time = Benchmark.realtime do
    response = super
    #=> [  status, headers, <#Raindrops::Middleware::Proxy> ]
    # Proxy is a wrapper around the response body
  end
  collect_http_metrics(env, response, time) if UnicornMetrics.http_metrics?
  response
end