Class: Prometheus::Middleware::Collector

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

Overview

Collector is a Rack middleware that provides a sample implementation of a HTTP tracer.

By default metrics are registered on the global registry. Set the ‘:registry` option to use a custom registry.

By default metrics all have the prefix “http_server”. Set to something else if you like.

The request counter metric is broken down by code, method and path by default. Set the ‘:counter_label_builder` option to use a custom label builder.

The request duration metric is broken down by method and path by default. Set the ‘:duration_label_builder` option to use a custom label builder.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Collector.



26
27
28
29
30
31
32
33
34
35
# File 'lib/prometheus/middleware/collector.rb', line 26

def initialize(app, options = {})
  @app = app
  @registry = options[:registry] || Client.registry
  @metrics_prefix = options[:metrics_prefix] || 'http_server'
  @counter_lb = options[:counter_label_builder] || COUNTER_LB
  @duration_lb = options[:duration_label_builder] || DURATION_LB

  init_request_metrics
  init_exception_metrics
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



24
25
26
# File 'lib/prometheus/middleware/collector.rb', line 24

def app
  @app
end

#registryObject (readonly)

Returns the value of attribute registry.



24
25
26
# File 'lib/prometheus/middleware/collector.rb', line 24

def registry
  @registry
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



37
38
39
# File 'lib/prometheus/middleware/collector.rb', line 37

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