class Tpt::Rails::PumaStatsCollector::PumaStats

Public Class Methods

new(stats) click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 3
def initialize(stats)
  @stats = JSON.parse(stats, symbolize_names: true)
end

Public Instance Methods

backlog() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 23
def backlog
  get_stat(:backlog)
end
booted_workers() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 15
def booted_workers
  @stats.fetch(:booted_workers, 1)
end
clustered?() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 7
def clustered?
  @stats.has_key?(:workers)
end
max_threads() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 31
def max_threads
  get_stat(:max_threads)
end
pool_capacity() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 27
def pool_capacity
  get_stat(:pool_capacity)
end
running() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 19
def running
  get_stat(:running)
end
to_s() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 35
def to_s
  {
    workers: workers,
    booted_workers: booted_workers,
    running: running,
    backlog: backlog,
    pool_capacity: pool_capacity,
    max_threads: max_threads
  }.to_json
end
workers() click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 11
def workers
  @stats.fetch(:workers, 1)
end

Private Instance Methods

get_stat(name) click to toggle source
# File lib/tpt/rails/puma_stats_collector.rb, line 47
def get_stat(name)
  if clustered?
    @stats[:worker_status].map { |s| s[:last_status].fetch(name, 0) }.sum
  else
    @stats.fetch(name, 0)
  end
end