mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add /stats, /stats/queues, & /stats/queues/:name json endpoints to web
This commit is contained in:
parent
f69d159ea0
commit
cff1516bdd
2 changed files with 116 additions and 0 deletions
|
@ -225,6 +225,54 @@ module Sidekiq
|
|||
})
|
||||
end
|
||||
|
||||
get '/stats' do
|
||||
sidekiq_stats = Sidekiq::Stats.new
|
||||
queues = Sidekiq::Queue.all
|
||||
|
||||
content_type :json
|
||||
Sidekiq.dump_json(
|
||||
processed: sidekiq_stats.processed,
|
||||
failed: sidekiq_stats.failed,
|
||||
busy: workers_size,
|
||||
enqueued: sidekiq_stats.enqueued,
|
||||
scheduled: sidekiq_stats.scheduled_size,
|
||||
retries: sidekiq_stats.retry_size,
|
||||
dead: sidekiq_stats.dead_size,
|
||||
queues: {
|
||||
count: queues.size,
|
||||
href: "#{uri}/queues"
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
get '/stats/queues' do
|
||||
queues = Sidekiq::Queue.all
|
||||
|
||||
queue_sizes = queues.reduce({}) do |ret, queue|
|
||||
ret[queue.name] = {
|
||||
depth: queue.size,
|
||||
href: "#{uri}/#{queue.name}"
|
||||
}
|
||||
ret
|
||||
end
|
||||
|
||||
content_type :json
|
||||
Sidekiq.dump_json(
|
||||
queue_sizes
|
||||
)
|
||||
end
|
||||
|
||||
get '/stats/queues/:name' do
|
||||
queue = Sidekiq::Queue.new(params[:name])
|
||||
|
||||
content_type :json
|
||||
Sidekiq.dump_json(
|
||||
name: queue.name,
|
||||
depth: queue.size,
|
||||
href: uri
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def retry_or_delete_or_kill job, params
|
||||
|
|
|
@ -355,6 +355,74 @@ class TestWeb < Sidekiq::Test
|
|||
describe 'stats' do
|
||||
include Sidekiq::Util
|
||||
|
||||
before do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.set("stat:processed", 5)
|
||||
conn.set("stat:failed", 2)
|
||||
conn.sadd("queues", "default")
|
||||
end
|
||||
2.times { add_retry }
|
||||
3.times { add_scheduled }
|
||||
4.times { add_worker }
|
||||
|
||||
get '/stats'
|
||||
@response = Sidekiq.load_json(last_response.body)
|
||||
end
|
||||
|
||||
it 'reports processed' do
|
||||
assert_equal 5, @response["processed"]
|
||||
end
|
||||
|
||||
it 'reports failed' do
|
||||
assert_equal 2, @response["failed"]
|
||||
end
|
||||
|
||||
it 'reports busy' do
|
||||
assert_equal 4, @response["busy"]
|
||||
end
|
||||
|
||||
it 'reports retries' do
|
||||
assert_equal 2, @response["retries"]
|
||||
end
|
||||
|
||||
it 'reports scheduled' do
|
||||
assert_equal 3, @response["scheduled"]
|
||||
end
|
||||
|
||||
it 'reports queue count' do
|
||||
assert_equal 1, @response["queues"]["count"]
|
||||
end
|
||||
|
||||
describe 'queues' do
|
||||
before do
|
||||
get '/stats/queues'
|
||||
@response = Sidekiq.load_json(last_response.body)
|
||||
end
|
||||
|
||||
it 'reports the queue depth' do
|
||||
assert_equal 0, @response["default"]["depth"]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'queues/:name' do
|
||||
before do
|
||||
get '/stats/queues/default'
|
||||
@response = Sidekiq.load_json(last_response.body)
|
||||
end
|
||||
|
||||
it 'reports the queue depth' do
|
||||
assert_equal 0, @response["depth"]
|
||||
end
|
||||
|
||||
it 'reports the queue name' do
|
||||
assert_equal 'default', @response["name"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dashboard/stats' do
|
||||
include Sidekiq::Util
|
||||
|
||||
before do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.set("stat:processed", 5)
|
||||
|
|
Loading…
Reference in a new issue