DEV Community

Alexander Budchanov for JetRockets

Posted on • Edited on • Originally published at jetrockets.pro

4 2

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}
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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'))
Enter fullscreen mode Exit fullscreen mode
  • 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}
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More