Sidekiq Stats in Rails


If you use Sidekiq in your Rails project, you can watch tasks statistics through the web interface. Usually, you can find it here: https://yourdomain.com/sidekiq (but in your project path may be different).

If you don't have access there, you can get the same data in Rails console.

To get statistics (number of tasks) by each queue:


Sidekiq::Stats.new.queues

=> {"local_cache"=>0, "default"=>0, "ts_delta"=>0, "mailchimp"=>0, "recorder"=>0}

Global statistics are available this way:


Sidekiq::Stats.new.fetch_stats!

=> {:processed=>61390,

 :failed=>3220,

 :scheduled_size=>0,

 :retry_size=>0,

 :dead_size=>4,

 :processes_size=>1,

 :default_queue_latency=>0,

 :workers_size=>0,

 :enqueued=>0}

The same stats are available separately:


stats = Sidekiq::Stats.new

stats.processed # number of processed tasks

stats.failed # number of failed tasks

stats.enqueued # number of enqueued tasks

and etc.

Also Sidekiq::Stats allows to look historical data. You can specify period. Something like:


s = Sidekiq::Stats::History.new(2, Date.parse('2019-02-05'))

  • first argument: number of days,

  • second argument: date until which return stats (default value is today and can be omitted)


s.processed

=> {"2019-02-05"=>0, "2019-02-04"=>0}

s.failed

=> {"2019-02-05"=>0, "2019-02-04"=>0}


Alexander
Budchanov

Backend Developer at JetRockets

Explore more of JetRockets