Skip to content

Instantly share code, notes, and snippets.

@matsimitsu
Created October 10, 2016 16:56
Show Gist options
  • Save matsimitsu/4332b9593d2b94705aa03b7ee2604803 to your computer and use it in GitHub Desktop.
Save matsimitsu/4332b9593d2b94705aa03b7ee2604803 to your computer and use it in GitHub Desktop.
-
title: 'Sidekiq Queues'
graphs:
-
title: 'Sidekiq Queue count'
kind: count
filter: queue_(.+)_count
format: number
-
title: 'Sidekiq Queue durations'
kind: measurement
filter: queue_(.+)_duration
format: duration
class SidekiqQueuePlugin
def call(worker, item, queue)
# Get time before the job in unix epoch float
before = Time.now.to_f
# Run the job
yield
# Get time after the job in unix epoch float
after = Time.now.to_f
# Count the number of jobs
Appsignal.increment_counter("queue_#{queue}_count", 1)
# Measure the time it took for the job to complete.
# (end - start) * 1000 to convert unix epoch float to miliseconds
Appsignal.add_distribution_value("queue_#{queue}_duration", (after - before) * 1000)
end
end
# Add plugin to Sidekiq middleware
::Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add SidekiqQueuePlugin
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment