Class: Prometheus::Middleware::Exporter
- Inherits:
-
Object
- Object
- Prometheus::Middleware::Exporter
- Defined in:
- lib/prometheus/middleware/exporter.rb
Overview
Exporter is a Rack middleware that provides a sample implementation of a Prometheus HTTP exposition endpoint.
By default it will export the state of the global registry and expose it under ‘/metrics`. Use the `:registry` and `:path` options to change the defaults.
Constant Summary collapse
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(app, options = {}) ⇒ Exporter
Returns a new instance of Exporter.
20 21 22 23 24 25 26 |
# File 'lib/prometheus/middleware/exporter.rb', line 20 def initialize(app, = {}) @app = app @registry = [:registry] || Client.registry @path = [:path] || '/metrics' @port = [:port] @acceptable = build_dictionary(FORMATS, FALLBACK) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'lib/prometheus/middleware/exporter.rb', line 15 def app @app end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/prometheus/middleware/exporter.rb', line 15 def path @path end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
15 16 17 |
# File 'lib/prometheus/middleware/exporter.rb', line 15 def registry @registry end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/prometheus/middleware/exporter.rb', line 28 def call(env) if metrics_port?(env['SERVER_PORT']) && env['PATH_INFO'] == @path format = negotiate(env, @acceptable) format ? respond_with(format) : not_acceptable(FORMATS) else @app.call(env) end end |