Skip to content

Pro Metrics

Mike Perham edited this page Dec 8, 2021 · 18 revisions

Sidekiq Pro can send runtime metrics to Statsd for distribution. Set up a global metrics handler and add the middleware to track job execution.

Enabling Metrics

require 'datadog/statsd' # gem 'dogstatsd-ruby'

# Be careful here.  I've found that when using UDP, Statsd can perform a DNS lookup
# on this hostname for every single packet. This can lead to mysterious but severe
# performance issues.
#
# You might consider installing a local caching DNS resolver instead (e.g. dnsmasq)
# or performing the DNS resolution once, here in the initializer.
#
Sidekiq::Pro.dogstatsd = ->{ Datadog::Statsd.new("metrics.example.com", 8125) }

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    require 'sidekiq/middleware/server/statsd'
    chain.add Sidekiq::Middleware::Server::Statsd
  end
end

Importing Statsd

Other metrics systems will have ingesters for importing Statsd metric data into their native format:

Metrics

Sidekiq Pro will send the following metrics for each job:

jobs.count => counter
jobs.success => counter
jobs.failure => counter
jobs.perform => gauge (time)

i.e. count will always be incremented. success or failure will be incremented based on the outcome. perform tracks the amount of time (in milliseconds) spent in the worker. Your Statsd system may provide additional metrics based on these explicit ones..

Tags

Sidekiq Pro sends several tags with each metric. Some Statsd platforms will accept these tags and allow you to visualize/report the perform metrics based on these additional dimensions:

tags: ["worker:VideoEncodeWorker", "queue:bulk"] 

Commercial Metrics

Several other metrics are sent for various Pro and Enterprise features:

jobs.expired - when a job is expired
jobs.recovered.push - when a job is recovered by reliable_push after network outage
jobs.recovered.fetch - when a job is recovered by super_fetch after process crash
jobs.poison - when a poison pill job is detected and killed by super_fetch
batch.created - when a batch is created
batch.complete - when a batch is completed
batch.success - when a batch is successful