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

Move /dashboard/stats to /stats and redirect

This commit is contained in:
Moser, Kevin 2014-12-26 09:46:35 -08:00
parent 0973426363
commit 38f601ccc8
2 changed files with 39 additions and 66 deletions

View file

@ -205,12 +205,16 @@ module Sidekiq
REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human)
get '/dashboard/stats' do
redirect "#{root_path}stats"
end
get '/stats' do
sidekiq_stats = Sidekiq::Stats.new
queue = Sidekiq::Queue.new
redis_stats = redis_info.select{ |k, v| REDIS_KEYS.include? k }
redis_stats = redis_info.select { |k, v| REDIS_KEYS.include? k }
content_type :json
Sidekiq.dump_json({
Sidekiq.dump_json(
sidekiq: {
processed: sidekiq_stats.processed,
failed: sidekiq_stats.failed,
@ -219,24 +223,9 @@ module Sidekiq
scheduled: sidekiq_stats.scheduled_size,
retries: sidekiq_stats.retry_size,
dead: sidekiq_stats.dead_size,
default_latency: queue.latency,
default_latency: queue.latency
},
redis: redis_stats
})
end
get '/stats' do
sidekiq_stats = Sidekiq::Stats.new
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
)
end

View file

@ -352,6 +352,14 @@ class TestWeb < Sidekiq::Test
end
end
describe 'dashboard/stats' do
it 'redirects to stats' do
get '/dashboard/stats'
assert_equal 302, last_response.status
assert_equal 'http://example.org/stats', last_response.header['Location']
end
end
describe 'stats' do
include Sidekiq::Util
@ -369,54 +377,6 @@ class TestWeb < Sidekiq::Test
@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
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"]
end
end
end
describe 'dashboard/stats' do
include Sidekiq::Util
before do
Sidekiq.redis do |conn|
conn.set("stat:processed", 5)
conn.set("stat:failed", 2)
end
2.times { add_retry }
3.times { add_scheduled }
4.times { add_worker }
get '/dashboard/stats'
@response = Sidekiq.load_json(last_response.body)
end
it 'can refresh dashboard stats' do
assert_equal 200, last_response.status
end
@ -478,6 +438,30 @@ class TestWeb < Sidekiq::Test
end
end
describe 'stats/queues' do
include Sidekiq::Util
before do
Sidekiq.redis do |conn|
conn.set("stat:processed", 5)
conn.set("stat:failed", 2)
conn.sadd("queues", "default")
conn.sadd("queues", "queue2")
end
2.times { add_retry }
3.times { add_scheduled }
4.times { add_worker }
get '/stats/queues'
@response = Sidekiq.load_json(last_response.body)
end
it 'reports the queue depth' do
assert_equal 0, @response["default"]
assert_equal 0, @response["queue2"]
end
end
describe 'dead jobs' do
it 'shows empty index' do
get 'morgue'