Class: ThreeScale::Backend::Rack::Prometheus

Inherits:
Object
  • Object
show all
Defined in:
lib/3scale/backend/rack/prometheus.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Prometheus

Returns a new instance of Prometheus.



5
6
7
# File 'lib/3scale/backend/rack/prometheus.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/3scale/backend/rack/prometheus.rb', line 9

def call(env)
  began_at = Time.now.getutc

  begin
    status, header, body = @app.call(env)
  rescue Exception => e
    ListenerMetrics.report_resp_code(env['REQUEST_PATH'], 500)
    ListenerMetrics.report_response_time(env['REQUEST_PATH'], Time.now - began_at)
    raise e
  end

  ListenerMetrics.report_resp_code(env['REQUEST_PATH'], status)
  ListenerMetrics.report_response_time(env['REQUEST_PATH'], Time.now - began_at)
  [status, header, body]
end