62

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?

phs
  • 10,687
  • 4
  • 58
  • 84
AgostinoX
  • 7,477
  • 20
  • 77
  • 137

7 Answers7

124

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)

Paul Keen
  • 1,360
  • 1
  • 9
  • 11
  • 9
    The API has been updated to now accept which stats you want to reset [source](https://github.com/mperham/sidekiq/blob/v4.0.1/lib/sidekiq/api.rb#L95). So you can now clear specific stats `Sidekiq::Stats.new.reset('failed')` or multiple stats `Sidekiq::Stats.new.reset('failed', 'processed')`. – tmr08c Dec 30 '15 at 20:58
  • This seems like the more preferred solution and IMO should be the selected answer – Ben Feb 01 '18 at 03:50
113

To reset processed jobs:

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

and to reset failed jobs:

Sidekiq.redis {|c| c.del('stat:failed') }
Roberto Barros
  • 1,491
  • 1
  • 12
  • 10
11

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.

Mikel Lindsaar
  • 241
  • 3
  • 6
5

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

Victor Hugo
  • 51
  • 1
  • 2
4

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
Paulo Victor
  • 3,814
  • 2
  • 26
  • 29
1

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
Milovan Zogovic
  • 1,541
  • 2
  • 16
  • 24
-5

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

Sidekiq.redis {|c| c.flushdb }
user1320651
  • 808
  • 2
  • 15
  • 42
  • 1
    This is a nuclear option and will drop everything in that Redis database, not just Sidekiq stats. That means you would lose any new Sidekiq jobs, any sessions, and any other data you happen to be using Redis for. – Parker Selbert Sep 27 '17 at 16:26
  • Thanks Parker, I was in the middle of something and hadnt finished the post but yes you are 100% correct. – user1320651 Sep 27 '17 at 16:32
  • The nuclear option can be very useful when you're working on a staging/development server. Thank you for this. – Jesse Farmer Apr 04 '19 at 10:00