Class: Prometheus::Client::Rack::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus/client/rack/collector.rb

Overview

Collector is a Rack middleware that provides a sample implementation of a Prometheus HTTP client API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}, &label_builder) ⇒ Collector

Returns a new instance of Collector.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/prometheus/client/rack/collector.rb', line 13

def initialize(app, options = {}, &label_builder)
  @app = app
  @registry = options[:registry] || Client.registry
  @label_builder = label_builder || proc do |env|
    {
      method: env['REQUEST_METHOD'].downcase,
      path:   env['PATH_INFO'].to_s,
    }
  end

  init_request_metrics
  init_exception_metrics
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/prometheus/client/rack/collector.rb', line 11

def app
  @app
end

#registryObject (readonly)

Returns the value of attribute registry.



11
12
13
# File 'lib/prometheus/client/rack/collector.rb', line 11

def registry
  @registry
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



27
28
29
# File 'lib/prometheus/client/rack/collector.rb', line 27

def call(env) # :nodoc:
  trace(env) { @app.call(env) }
end