Puma Stats Logger
For Rack apps (including Rails)
This Rack middleware gathers statistics from Puma web server and logs them to the logging destination of your choice. It uses Puma's built in control server to query Puma's stats after every request in your production application. Currently, Puma provides two metrics that are output to your logs:
- running - the number of threads currently running
- backlog - the number of requests waiting to be processed by a thread
The actual log entry looks like this:
Add the gem to your gemfile:
Enable Puma's control/stats server & state file
If you use a Puma configuration file, add the following two lines:
# in config/puma.rb activate_control_app state_path 'tmp/puma.state'
OR ... if you don't use a Puma config file and you start Puma via command line, add these options:
puma --control auto --state "tmp/puma.state"
Activate the Middleware in your app
In your application and/or environment config:
or in a Rails initializer:
Changing the logging destination
By default, the Puma stats are logged to standard output
$stdout. This works great out of the box for Heroku users. You can customize this by passing an option hash:
config.middleware.use ::, logger: Logger.new('destination/puma-stats.log')
We use the Librato add-on on Heroku to make nice charts of this data. You may have noticed that the log output is already formatted for Librato, so if you're already using Librato, Puma metrics should show up automatically under Metrics.
Open Source by Hired
Hired is a marketplace for top engineering talent to find full-time technology jobs. Talented Ruby developers (like yourself) are in extremely high demand! On Hired, apply once and receive 5 to 15 competing job offers in one week from 800+ technology companies. Average Ruby engineer salaries on Hired are around $120,000 per year!
We are Ruby developers ourselves, and we use all of our open source projects in production. We always encourge forks, pull requests, and issues. Get in touch with the Hired Engineering team at [email protected].