How do I reset my sidekiq counters?

Ruby on-RailsRubySidekiq

Ruby on-Rails Problem Overview


In my sidekiq dashboard, I see on the left a box with the counters

Processed 168
Failed 111
Busy 0
Scheduled 0
Retries 0
Enqueued 0

How do I reset them all to 0?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

To reset statistics:

Sidekiq::Stats.new.reset

ref: Add reset stats to Web UI summary box and method to API

Also, you can now clear specific stats:

  • single stat by Sidekiq::Stats.new.reset('failed')
  • or multiple stats by Sidekiq::Stats.new.reset('failed', 'processed')

(Thanks https://stackoverflow.com/users/2475008/tmr08c for update)

Solution 2 - Ruby on-Rails

To reset processed jobs:

Sidekiq.redis {|c| c.del('stat:processed') }

and to reset failed jobs:

Sidekiq.redis {|c| c.del('stat:failed') }

Solution 3 - Ruby on-Rails

Also, to reset specific days in the history panel, you can do:

Sidekiq.redis {|c| c.del('stat:processed:2015-07-02') }
Sidekiq.redis {|c| c.del('stat:failed:2015-07-02') }

And repeat for each day you want to clear.

This is useful if you had a wild job spawning and failing many times more than your usual and you get a history graph with a massive spike in it that makes all your usual history values effectively a flat line.

Solution 4 - Ruby on-Rails

1. Clear retry set

Sidekiq::RetrySet.new.clear

2. Clear scheduled jobs

Sidekiq::ScheduledSet.new.clear

3. Clear 'Processed' and 'Failed' jobs

Sidekiq::Stats.new.reset

3. Clear 'Dead' jobs statistics

Sidekiq::DeadSet.new.clear

Font: https://gist.github.com/wbotelhos/fb865fba2b4f3518c8e533c7487d5354

Solution 5 - Ruby on-Rails

Just to complement all good answers, reset counters using ruby interactive mode, doing this into console:

irb
irb(main):001:0> require 'sidekiq/api'
=> true
irb(main):002:0> Sidekiq.redis {|c| c.del('stat:processed') }
=> 1
irb(main):003:0> Sidekiq.redis {|c| c.del('stat:failed') }
=> 1

Solution 6 - Ruby on-Rails

In case you want to delete the whole thing along with the history panel for specific dates, here is the helpful snippet:

from_date = Date.new(2016, 1, 1)
to_date = Date.today

Sidekiq.redis do |redis|
  redis.del("stat:processed")
  redis.del("stat:failed")
  
  (from_date..to_date).each do |date|
    redis.del("stat:processed:#{date}")
    redis.del("stat:failed:#{date}")
  end
end

Solution 7 - Ruby on-Rails

This will also reset the history and delete everything from the Redis queue completely

Sidekiq.redis {|c| c.flushdb }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAgostinoXView Question on Stackoverflow
Solution 1 - Ruby on-RailsPaul KeenView Answer on Stackoverflow
Solution 2 - Ruby on-RailsRoberto BarrosView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMikel LindsaarView Answer on Stackoverflow
Solution 4 - Ruby on-RailsVictor HugoView Answer on Stackoverflow
Solution 5 - Ruby on-RailsPaulo VictorView Answer on Stackoverflow
Solution 6 - Ruby on-RailsMilovan ZogovicView Answer on Stackoverflow
Solution 7 - Ruby on-Railsuser1320651View Answer on Stackoverflow