class Object
Public Instance Methods
find_and_log_pool_usage()
click to toggle source
Find the Puma stats necessary depending on mode (single vs. cluster). Sends statistics for logging.
# File lib/puma/plugin/pool_usage.rb, line 33 def find_and_log_pool_usage stats = JSON.parse(Puma.stats, symbolize_names: true) if stats[:worker_status] stats[:worker_status].each { |worker| log_pool_usage(worker[:last_status], pid: worker[:pid]) } else log_pool_usage(stats, pid: 0) end end
log_pool_usage(status, pid:)
click to toggle source
Calculate and log, assuing Puma has started and provided stats.
@param [Hash] status Puma statistics. @param [Integer] pid Process identifier for this particular Puma worker.
# File lib/puma/plugin/pool_usage.rb, line 47 def log_pool_usage(status, pid:) return if status[:pool_capacity].nil? pool_usage = (status[:running] - (status[:pool_capacity] - status[:backlog])) / status[:running].to_f Rails.logger.info "source=PUMA pid=#{pid} sample#pool_usage=#{pool_usage}" end
start(_launcher)
click to toggle source
Method called by Puma on startup.
@param [Puma::Launcher] _launcher Puma launcher object, ignored.
# File lib/puma/plugin/pool_usage.rb, line 19 def start(_launcher) in_background do loop do sleep ENV.fetch("PUMA_STATS_FREQUENCY", 60).to_i find_and_log_pool_usage Rails.logger.flush end end end