title | type | tags | metaDescription | redirects | freshnessValidatedDate | |||
---|---|---|---|---|---|---|---|---|
Incorrect counts with Unicorn |
troubleshooting |
|
Troubleshooting for New Relic Ruby APM monitoring for use of Unicorn when metric and custom event metrics seem too low. |
never |
You're using New Relic Ruby APM and Unicorn together, but the counts for metrics and custom events seem too small.
Have Unicorn manually call NewRelic::Agent.shutdown
to run the agent's exit handlers. Some of Unicorn's exit methods prevent the agent from shutting down as expected. The change below runs New Relic's shutdown method before killing the Unicorn process.
This fix relies on @expectedbehavior's fork of the unicorn-worker-killer gem.
- Add this to your Gemfile using:
gem 'unicorn-worker-killer', git: 'https://github.com/expectedbehavior/unicorn-worker-killer'
If you're already using unicorn-worker-killer
in your Gemfile, update the reference to use this fork.
- Bundle:
bundle install
- Update your unicorn configuration to include:
require "unicorn/worker_killer"
::Unicorn::WorkerKiller.configure do |config|
config.before_kill do |signal|
::NewRelic::Agent.increment_metric("Custom/UnicornWorkerBeforeKillSignal/#{signal}")
::NewRelic::Agent.shutdown
end
end
- Restart your server