Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of Hash-shaped stats #18

Merged
merged 1 commit into from Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/puma/metrics/app.rb
Expand Up @@ -14,13 +14,22 @@ def initialize(launcher)
end

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

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
end
end
end
8 changes: 4 additions & 4 deletions lib/puma/metrics/parser.rb
Expand Up @@ -10,10 +10,10 @@ def initialize(clustered = false)
register_clustered_metrics if clustered
end

def parse(stats, labels = {})
stats.each do |key, value|
value.each { |s| parse(s, labels.merge(index: s['index'])) } if key == 'worker_status'
parse(value, labels) if key == 'last_status'
def parse(symbol_keyed_stats, labels = {})
symbol_keyed_stats.each do |key, value|
value.each { |s| parse(s, labels.merge(index: s[:index])) } if key == :worker_status
parse(value, labels) if key == :last_status
update_metric(key, value, labels)
end
end
Expand Down