Skip to content

Commit

Permalink
Merge pull request sidekiq#2141 from ismaelga/patch-1
Browse files Browse the repository at this point in the history
Add processes count to /stats
  • Loading branch information
mperham committed Jan 16, 2015
2 parents cd7e160 + 40f627a commit 87d2b3b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HEAD
- Log Sidekiq Pro's Batch ID if available [#2076]
- Refactor Processor Redis usage to avoid redis/redis-rb#490 [#]
- Move /dashboard/stats to /stats. Add /stats/queues. [moserke, #2099]
- Add processes count to /stats [ismaelga, #2141]
- Add better usage text for `sidekiqctl`.
- `Sidekiq::Logging.with_context` is now a stack so you can set your
own job context for logging purposes [grosser, #2110]
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def each(&block)
end
end

result.each_with_index do |(info, busy, at_s), i|
result.each do |info, busy, at_s|
hash = Sidekiq.load_json(info)
yield Process.new(hash.merge('busy' => busy.to_i, 'beat' => at_s.to_f))
end
Expand Down
3 changes: 2 additions & 1 deletion lib/sidekiq/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def custom_tabs
p.quiet! if params[:quiet]
p.stop! if params[:stop]
else
Sidekiq::ProcessSet.new.each do |pro|
processes.each do |pro|
pro.quiet! if params[:quiet]
pro.stop! if params[:stop]
end
Expand Down Expand Up @@ -219,6 +219,7 @@ def custom_tabs
processed: sidekiq_stats.processed,
failed: sidekiq_stats.failed,
busy: workers_size,
processes: processes_size,
enqueued: sidekiq_stats.enqueued,
scheduled: sidekiq_stats.scheduled_size,
retries: sidekiq_stats.retry_size,
Expand Down
8 changes: 8 additions & 0 deletions lib/sidekiq/web_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def workers
@workers ||= Sidekiq::Workers.new
end

def processes_size
@processes_size ||= processes.size
end

def processes
@processes ||= Sidekiq::ProcessSet.new
end

def stats
@stats ||= Sidekiq::Stats.new
end
Expand Down
6 changes: 5 additions & 1 deletion test/test_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ def perform(a, b)
assert_equal 4, @response["sidekiq"]["busy"]
end

it 'reports processes' do
assert_equal 1, @response["sidekiq"]["processes"]
end

it 'reports retries' do
assert_equal 2, @response["sidekiq"]["retries"]
end
Expand Down Expand Up @@ -568,7 +572,7 @@ def add_worker
Sidekiq.redis do |conn|
conn.multi do
conn.sadd("processes", key)
conn.hmset(key, 'busy', 4)
conn.hmset(key, 'info', Sidekiq.dump_json('hostname' => 'foo', 'started_at' => Time.now.to_f, "queues" => []), 'at', Time.now.to_f, 'busy', 4)
conn.hmset("#{key}:workers", Time.now.to_f, msg)
end
end
Expand Down
4 changes: 2 additions & 2 deletions web/views/busy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<th><%= t('Busy') %></th>
<th>&nbsp;</th>
</thead>
<% Sidekiq::ProcessSet.new.each do |process| %>
<% processes.each do |process| %>
<tr>
<td width="50%">
<%= "#{process['hostname']}:#{process['pid']}" %>
Expand Down Expand Up @@ -65,7 +65,7 @@
<th><%= t('Arguments') %></th>
<th><%= t('Started') %></th>
</thead>
<% workers.each_with_index do |(process, thread, msg), index| %>
<% workers.each do |process, thread, msg| %>
<% job = Sidekiq::Job.new(msg['payload']) %>
<tr>
<td><%= process %></td>
Expand Down

0 comments on commit 87d2b3b

Please sign in to comment.