Problem
You're using New Relic Ruby APM and Unicorn together, but the counts for metrics and custom events seem too small.
Solution
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:
bash$bundle installUpdate 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.shutdownendendRestart your server