Class: Leafy::Rack::Metrics

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

Constant Summary collapse

WRITER =
::Leafy::Json::MetricsWriter.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, registry, path = '/metrics') ⇒ Metrics

Returns a new instance of Metrics.



20
21
22
23
24
# File 'lib/leafy/rack/metrics.rb', line 20

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

Class Method Details

.response(metrics, env) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/leafy/rack/metrics.rb', line 11

def self.response( metrics, env )
  [ 
   200, 
   { 'Content-Type' => 'application/json',
     'Cache-Control' => 'must-revalidate,no-cache,no-store' }, 
   [ WRITER.to_json( metrics, env[ 'QUERY_STRING' ] == 'pretty' ) ]
  ]
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/leafy/rack/metrics.rb', line 26

def call(env)
  if env['PATH_INFO'] == @path
    Metrics.response( @registry.metrics, env )
  else
    @app.call( env )
  end
end