1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/stats.rb

37 lines
944 B
Ruby
Raw Normal View History

2012-09-03 13:37:54 -04:00
module Sidekiq
module_function
2012-09-03 13:37:54 -04:00
def info
results = {}
2012-09-04 12:59:02 -04:00
processed, failed, queues = Sidekiq.redis { |conn|
conn.multi do
conn.get('stat:processed')
conn.get('stat:failed')
conn.smembers('queues')
end
}
2012-09-04 01:41:32 -04:00
results[:queues_with_sizes] = Sidekiq.redis do |conn|
2012-09-04 12:59:02 -04:00
queues.inject({}) { |memo, q|
memo[q] = conn.llen("queue:#{q}")
memo
}.sort_by { |_, size| size }
2012-09-03 13:43:08 -04:00
end
2012-09-04 12:59:02 -04:00
results[:processed] = (processed || 0).to_i
results[:failed] = (failed || 0).to_i
2012-09-04 01:41:32 -04:00
results[:backlog] = results[:queues_with_sizes].
map {|_, size| size }.
inject(0) {|memo, val| memo + val }
results
end
2012-12-04 12:13:47 -05:00
def size(*queues)
return info[:backlog] if queues.empty?
Sidekiq.redis { |conn|
conn.multi {
queues.map { |q| conn.llen("queue:#{q}") }
}
}.inject(0) { |memo, count| memo += count }
end
2012-09-03 13:37:54 -04:00
end