Class: Puma::Metrics::App

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

Instance Method Summary collapse

Constructor Details

#initialize(launcher) ⇒ App

Returns a new instance of App.



10
11
12
13
14
# File 'lib/puma/metrics/app.rb', line 10

def initialize(launcher)
  @launcher = launcher
  clustered = (@launcher.options[:workers] || 0) > 0
  @parser = Parser.new(clustered: clustered)
end

Instance Method Details

#call(_env) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/puma/metrics/app.rb', line 16

def call(_env)
  retrieve_and_parse_stats!
  [
    200,
    { 'Content-Type' => 'text/plain' },
    [Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
  ]
end

#retrieve_and_parse_stats!Object



25
26
27
28
29
30
31
32
# File 'lib/puma/metrics/app.rb', line 25

def retrieve_and_parse_stats!
  puma_stats = @launcher.stats
  if puma_stats.is_a?(Hash) # Modern Puma outputs stats as a Symbol-keyed Hash
    @parser.parse(puma_stats)
  else
    @parser.parse(JSON.parse(puma_stats, symbolize_names: true))
  end
end