docs/stats.md
Stats can be accessed in two ways:
$ pumactl stats or GET /stats
Read more about pumactl and the control server in the README..
Puma.stats produces a JSON string. Puma.stats_hash produces a ruby hash.
Invoke Puma.stats anywhere in runtime, e.g. in a rails initializer:
# config/initializers/puma_stats.rb
Thread.new do
loop do
sleep 30
puts Puma.stats
end
end
Invoke Puma.stats from the master process
# config/puma.rb
before_fork do
Thread.new do
loop do
puts Puma.stats
sleep 30
end
end
end
Puma.stats returns different information and a different structure depending on if Puma is in single vs. cluster mode. There is one top-level attribute that is common to both modes:
When Puma runs in single mode, these stats are available at the top level. When Puma runs in cluster mode, these stats are available within the worker_status array in a hash labeled last_status, in an array of hashes where one hash represents each worker.
min_threads and max_threads are set to the same number,
this will be a never-changing number (other than rare cases when a thread dies, etc).running - how many threads are waiting to receive work + how many requests are waiting for a thread to pick them up.
this is a "wholistic" stat reflecting the overall current state of work to be done and the capacity to do it.how many threads are waiting to receive work + max_threads - running. In a typical configuration where min_threads
and max_threads are configured to the same number, this is simply how many threads are waiting to receive work. This number exists only as a stat
and is not used for any internal decisions, unlike busy_threads, which is usually a more useful stat.Here are two example stats hashes produced by Puma.stats:
{
"started_at": "2021-01-14T07:12:35Z",
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 3
}
{
"started_at": "2021-01-14T07:09:17Z",
"workers": 2,
"phase": 0,
"booted_workers": 2,
"old_workers": 0,
"worker_status": [
{
"started_at": "2021-01-14T07:09:24Z",
"pid": 64136,
"index": 0,
"phase": 0,
"booted": true,
"last_checkin": "2021-01-14T07:11:09Z",
"last_status": {
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 2
}
},
{
"started_at": "2021-01-14T07:09:24Z",
"pid": 64137,
"index": 1,
"phase": 0,
"booted": true,
"last_checkin": "2021-01-14T07:11:09Z",
"last_status": {
"backlog": 0,
"running": 5,
"pool_capacity": 5,
"max_threads": 5,
"requests_count": 1
}
}
]
}