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

38 lines
1 KiB
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 = {}
futures = {}
queues_with_sizes = Sidekiq.redis { |conn|
conn.pipelined do
futures[:processed] = conn.get('stat:processed')
futures[:failed] = conn.get('stat:failed')
futures[:queues] = conn.smembers('queues')
end
}
2012-09-04 01:41:32 -04:00
results[:queues_with_sizes] = Sidekiq.redis do |conn|
futures[:queues].value.inject({}) { |memo, q|
memo[q] = conn.llen("queue:#{q}")
memo
}.sort_by { |_, size| size }
2012-09-03 13:43:08 -04:00
end
results[:processed] = (futures[:processed].value || 0).to_i
results[:failed] = (futures[:failed].value || 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-09-03 13:43:08 -04:00
def size(*queues)
return info[:backlog] if queues.empty?
2012-09-04 01:55:25 -04:00
Sidekiq.redis { |conn|
conn.pipelined {
queues.map { |q| conn.llen("queue:#{q}") }
}
2012-09-04 01:55:25 -04:00
}.inject(0) { |memo, count| memo += count }
2012-09-03 13:37:54 -04:00
end
end