Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add process/thread count summary to Busy page #4806

Merged
merged 6 commits into from Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -29,6 +29,7 @@ If this is a bare Rack app, use a session middleware before Sidekiq::Web:
use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
run Sidekiq::Web
```
- Add process/thread count summary to Busy page [#4806]

6.1.3
---------
Expand Down
13 changes: 12 additions & 1 deletion lib/sidekiq/api.rb
Expand Up @@ -806,7 +806,7 @@ def each
yield Process.new(hash.merge("busy" => busy.to_i,
"beat" => at_s.to_f,
"quiet" => quiet,
"rss" => rss))
"rss" => rss.to_i))
end
end

Expand All @@ -818,6 +818,17 @@ def size
Sidekiq.redis { |conn| conn.scard("processes") }
end

# Total number of threads available to execute jobs.
# For Sidekiq Enterprise customers this number (in production) must be
# less than or equal to your licensed concurrency.
def total_concurrency
sum { |x| x["concurrency"] }
end

def total_rss
sum { |x| x["rss"] || 0 }
end

# Returns the identity of the current cluster leader or "" if no leader.
# This is a Sidekiq Enterprise feature, will always return "" in Sidekiq
# or Sidekiq Pro.
Expand Down
12 changes: 11 additions & 1 deletion lib/sidekiq/web/helpers.rb
Expand Up @@ -22,6 +22,14 @@ def strings(lang)
end
end

def singularize(str, count)
if count == 1 && str.respond_to?(:singularize) # rails
str.singularize
else
str
end
end

def clear_caches
@strings = nil
@locale_files = nil
Expand Down Expand Up @@ -263,8 +271,10 @@ def format_memory(rss_kb)

if rss_kb < 100_000
"#{number_with_delimiter(rss_kb)} KB"
else
elsif rss_kb < 10_000_000
"#{number_with_delimiter((rss_kb / 1024.0).to_i)} MB"
else
"#{number_with_delimiter((rss_kb / (1024.0 * 1024.0)).round(1))} GB"
end
end

Expand Down
2 changes: 1 addition & 1 deletion web/assets/stylesheets/application.css
Expand Up @@ -186,7 +186,7 @@ form .btn {
}

form .btn-group .btn {
margin-right: 1px;
margin-right: 4px;
}

td form {
Expand Down
54 changes: 41 additions & 13 deletions web/views/busy.erb
@@ -1,8 +1,39 @@
<div class="row header">
<div class="col-sm-8 pull-left flip">
<div class="col-sm-4 pull-left flip">
<h3><%= t('Status') %></h3>
</div>
</div>

<div class="table_container">
<div class="stats-container">
<div class="stat">
<h3><%= s = processes.size; number_with_delimiter(s) %></h3>
<p><%= t('Processes') %></p>
</div>
<div class="stat">
<h3><%= x = processes.total_concurrency; number_with_delimiter(x) %></h3>
<p><%= t('Threads') %></p>
</div>
<div class="stat">
<h3><%= ws = workers.size; number_with_delimiter(ws) %></h3>
<p><%= t('Busy') %></p>
</div>
<div class="stat">
<h3><%= x == 0 ? 0 : ((ws / x.to_f) * 100).round(0) %>%</h3>
<p><%= t('Utilization') %></p>
</div>
<div class="stat">
<h3><%= format_memory(processes.total_rss) %></h3>
<p><%= t('RSS') %></p>
</div>
</div>
</div>

<div class="row header">
<div class="col-sm-4 pull-left flip">
<h3><%= t('Processes') %></h3>
</div>
<div class="col-sm-4 pull-right flip">
<div class="col-sm-3 pull-right flip">
<form method="POST" class="warning-messages">
<%= csrf_tag %>
<div class="btn-group pull-right flip">
Expand All @@ -12,15 +43,14 @@
</form>
</div>
</div>

<div class="table_container">
<table class="processes table table-hover table-bordered table-striped">
<thead>
<th><%= t('Name') %></th>
<th><%= t('Started') %></th>
<th><%= t('RSS') %><a href="https://github.com/mperham/sidekiq/wiki/Memory#rss"><span class="info-circle" title="Click to learn more about RSS">?</span></a></th>
<th><%= t('Threads') %></th>
<th><%= t('Busy') %></th>
<th class="col-sm-1"><%= t('RSS') %><a href="https://github.com/mperham/sidekiq/wiki/Memory#rss"><span class="info-circle" title="Click to learn more about RSS">?</span></a></th>
<th class="col-sm-1"><%= t('Threads') %></th>
<th class="col-sm-1"><%= t('Busy') %></th>
<th>&nbsp;</th>
</thead>
<% lead = processes.leader %>
Expand All @@ -47,16 +77,14 @@
<td><%= process['concurrency'] %></td>
<td><%= process['busy'] %></td>
<td>
<div class="btn-group pull-right flip">
<form method="POST">
<form method="POST">
<div class="btn-group pull-right flip">
<%= csrf_tag %>
<input type="hidden" name="identity" value="<%= process['identity'] %>"/>
<% unless process.stopping? %>
<button class="btn btn-warn" type="submit" name="quiet" value="1"><%= t('Quiet') %></button>
<% end %>
<% unless process.stopping? %><button class="btn btn-warn" type="submit" name="quiet" value="1"><%= t('Quiet') %></button><% end %>
<button class="btn btn-danger" type="submit" name="stop" value="1"><%= t('Stop') %></button>
</form>
</div>
</div>
</form>
</td>
</tr>
<% end %>
Expand Down