Class: Prometheus::Client::Rack::Exporter

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

Overview

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

Constant Summary collapse

FORMATS =
[Formats::Text, Formats::JSON]
FALLBACK =
Formats::JSON

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Exporter.



18
19
20
21
22
23
# File 'lib/prometheus/client/rack/exporter.rb', line 18

def initialize(app, options = {})
  @app = app
  @registry = options[:registry] || Client.registry
  @path = options[:path] || '/metrics'
  @acceptable = build_dictionary(FORMATS, FALLBACK)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/prometheus/client/rack/exporter.rb', line 13

def app
  @app
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/prometheus/client/rack/exporter.rb', line 13

def path
  @path
end

#registryObject (readonly)

Returns the value of attribute registry.



13
14
15
# File 'lib/prometheus/client/rack/exporter.rb', line 13

def registry
  @registry
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/prometheus/client/rack/exporter.rb', line 25

def call(env)
  if env['PATH_INFO'] == @path
    format = negotiate(env['HTTP_ACCEPT'], @acceptable)
    format ? respond_with(format) : not_acceptable(FORMATS)
  else
    @app.call(env)
  end
end