Class: Etna::MetricsExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/etna/metrics.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path: '/metrics') ⇒ MetricsExporter

Returns a new instance of MetricsExporter.



4
5
6
7
# File 'lib/etna/metrics.rb', line 4

def initialize(app, path: '/metrics')
  @app = app
  @path = path
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/etna/metrics.rb', line 18

def call(env)
  if env['PATH_INFO'] == @path
    exporter.call(env)
  else
    @app.call(env)
  end
end

#exporterObject



9
10
11
12
13
14
15
16
# File 'lib/etna/metrics.rb', line 9

def exporter
  @exporter ||= begin
    exporter = Yabeda::Prometheus::Exporter.new(@app, path: @path)
    Rack::Auth::Basic.new(exporter) do |user, pw|
      user == 'prometheus' && pw == ENV['METRICS_PW']
    end
  end
end