diff --git a/History.md b/History.md index d319d221b3..cc9ae55a3d 100644 --- a/History.md +++ b/History.md @@ -13,7 +13,7 @@ * New configuration option to set state file permissions (#2238) * Deprecations, Removals and Breaking API Changes - * `Puma.stats` now returns a Hash instead of a JSON string (#2086) + * `Puma.stats_hash` returns a Hash version of the stats (#2086, ) * `--control` has been removed. Use `--control-url` (#1487) * `worker_directory` has been removed. Use `directory`. * min_threads now set by environment variables PUMA_MIN_THREADS and MIN_THREADS. (#2143) diff --git a/lib/puma.rb b/lib/puma.rb index cb46f8ca35..bd667116f1 100644 --- a/lib/puma.rb +++ b/lib/puma.rb @@ -20,6 +20,10 @@ def self.stats_object=(val) end def self.stats + @get_stats.stats.to_json + end + + def self.stats_hash @get_stats.stats end diff --git a/test/test_cli.rb b/test/test_cli.rb index eb0f1e98b2..22597f06f7 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -55,6 +55,8 @@ def test_control_for_tcp body = s.read s.close + assert_equal Puma.stats_hash, JSON.parse(Puma.stats, symbolize_names: true) + dmt = Puma::Configuration.new.default_max_threads assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split(/\r?\n/).last) diff --git a/test/test_launcher.rb b/test/test_launcher.rb index 53505c3100..39fb7ab88d 100644 --- a/test/test_launcher.rb +++ b/test/test_launcher.rb @@ -139,7 +139,7 @@ def test_puma_stats launcher.events.on_booted {launcher.stop} launcher.run Puma::Server::STAT_METHODS.each do |stat| - assert_includes Puma.stats, stat + assert_includes Puma.stats_hash, stat end end @@ -154,7 +154,7 @@ def test_puma_stats_clustered launcher = launcher(conf) Thread.new do sleep Puma::Const::WORKER_CHECK_INTERVAL + 1 - status = Puma.stats[:worker_status].first[:last_status] + status = Puma.stats_hash[:worker_status].first[:last_status] Puma::Server::STAT_METHODS.each do |stat| assert_includes status, stat end