diff --git a/lib/puma/app/status.rb b/lib/puma/app/status.rb index 6f68c6b83e..58615d7db1 100644 --- a/lib/puma/app/status.rb +++ b/lib/puma/app/status.rb @@ -1,3 +1,5 @@ +require 'json' + module Puma module App class Status @@ -60,8 +62,7 @@ def call(env) return rack_response(200, OK_STATUS) when /\/gc-stats$/ - json = "{" + GC.stat.map { |k, v| "\"#{k}\": #{v}" }.join(",") + "}" - return rack_response(200, json) + return rack_response(200, GC.stat.to_json) when /\/stats$/ return rack_response(200, @cli.stats) diff --git a/test/test_cli.rb b/test/test_cli.rb index ceffef7e36..cadefd097a 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -1,6 +1,7 @@ require_relative "helper" require "puma/cli" +require "json" class TestCLI < Minitest::Test def setup @@ -195,12 +196,7 @@ def control_gc_stats(uri, cntl) lines = body.split("\r\n") json_line = lines.detect { |l| l[0] == "{" } - pairs = json_line.scan(/\"[^\"]+\": [^,]+/) - gc_stats = {} - pairs.each do |p| - p =~ /\"([^\"]+)\": ([^,]+)/ || raise("Can't parse #{p.inspect}!") - gc_stats[$1] = $2 - end + gc_stats = JSON.parse(json_line) gc_count_after = gc_stats["count"].to_i # Hitting the /gc route should increment the count by 1