Nightwing
Nightwing is a Sidekiq middleware for capturing worker metrics including number processed, number of failures, timing, etc.
Installation
Inside your Gemfile, add the following line:
gem 'nightwing'
Configuration
You will need to add the code below to your app. In a typical Rails app, this would go into an initializer.
Please note that you must require your own librato-rack gem and supply it to Nightwing
# config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add Nightwing::Sidekiq::Stats, client: Librato
chain.add Nightwing::Sidekiq::QueueStats, client: Librato
chain.add Nightwing::Sidekiq::WorkerStats, client: Librato
chain.add Nightwing::Sidekiq::Profiler, client: Librato
end
end
To gather database metrics:
# config/initializers/instrumentation.rb
Nightwing.client = Librato
ActiveSupport::Notifications.subscribe('sql.active_record', Nightwing::Instrumentation::ActiveRecord.new)
To gather Redis and memcache metrics:
# config/initializers/instrumentation.rb
Nightwing.client = Librato
require 'nightwing/extensions/dalli' # dalli gem required
require 'nightwing/extensions/redis' # redis gem required
Available options
Name | Description | Required? | Default |
---|---|---|---|
client | Librato or statsd client | yes | N/A |
namespace | Prefix for each metric | no | "sidekiq" |
debug | Enable for verbose logging | no | false |
logger | Logger instance for debug mode | no | Nightwing::Logger |
When debug mode is turned on, Nightwing will output the metrics into a parsable format. The output destination is determined by the logger. If no logger is given then we send the debugging output to STDOUT.
Instrumentation Metrics
Below are the metrics reported to Librato from instrumentation classes
sql.<table>.<action>.time
: how long the database query took to complete
Extensions Metrics
Below are the metrics reported to Librato from instrumentation classes
redis.command.processed
: number of times overall command was calledredis.command.time
: response time (in ms) for all commandsredis.command.<command>.processed
: number of times the command was calledredis.command.<command>.time
: response time (in ms) for commandmemcache.command.processed
: number of times overall command was calledmemcache.command.time
: response time (in ms) for all commandsmemcache.command.<command>.processed
: number of times the command was calledmemcache.command.<command>.time
: response time (in ms) for command
Sidekiq Metrics
Below are the metrics reported to Librato from the Sidekiq middleware
sidekiq.retries
: number of jobs to be retriedsidekiq.scheduled
: number of jobs scheduled to runsidekiq.processed
: number of times middleware calledsidekiq.failed
: number of jobs that raised an error
Queue specific
sidekiq.<queue>.size
: depth for a given queuesidekiq.<queue>.latency
: latency for given queue¹sidekiq.<queue>.processed
: number of times middleware called for given queuesidekiq.<queue>.failed
: number of jobs in given queue that raised an errorsidekiq.<queue>.time
: how long jobs took to process (in milliseconds)sidekiq.<queue>.gc.count
: number of times the Ruby GC kicked offsidekiq.<queue>.memory.delta
: the different in the process memory after jobs were processed (in bytes)
¹: the difference between now and when the oldest job was enqueued (given in seconds)
Worker specific
sidekiq.<queue>.<worker>.processed
: number of times middleware called for given workersidekiq.<queue>.<worker>.failed
: number of jobs in given worker that raised an errorsidekiq.<queue>.<worker>.finished
: number of successful worker jobssidekiq.<queue>.<worker>.time
: how long given worker took to process (in milliseconds)sidekiq.<queue>.<worker>.retried
: number of times a given worker retriedsidekiq.<queue>.<worker>.gc.count
: number of times the Ruby GC kicked offsidekiq.<queue>.<worker>.memory.delta
: the different in the process memory after jobs were processed (in bytes)