Class: Prometheus::Middleware::Collector
- Inherits:
-
Object
- Object
- Prometheus::Middleware::Collector
- 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.
Label Builder functions will receive a Rack env and a status code, and must return a hash with the labels for that request. They must also accept an empty env, and return a hash with the correct keys. This is necessary to initialize the metrics with the correct set of labels.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#call(env) ⇒ Object
:nodoc:.
-
#initialize(app, options = {}) ⇒ Collector
constructor
A new instance of Collector.
Constructor Details
#initialize(app, options = {}) ⇒ Collector
Returns a new instance of Collector.
31 32 33 34 35 36 37 38 |
# File 'lib/prometheus/middleware/collector.rb', line 31 def initialize(app, = {}) @app = app @registry = [:registry] || Client.registry @metrics_prefix = [:metrics_prefix] || 'http_server' init_request_metrics init_exception_metrics end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
29 30 31 |
# File 'lib/prometheus/middleware/collector.rb', line 29 def app @app end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
29 30 31 |
# File 'lib/prometheus/middleware/collector.rb', line 29 def registry @registry end |
Instance Method Details
#call(env) ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/prometheus/middleware/collector.rb', line 40 def call(env) # :nodoc: trace(env) { @app.call(env) } end |