Skip to content

Commit

Permalink
format numbers in reporting counters
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Sep 27, 2023
1 parent fd27f77 commit 9bffcc8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
5 changes: 3 additions & 2 deletions lib/karafka/web/ui/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ def format_memory(mem_kb)

# Converts number to a more friendly delimiter based version
# @param number [Numeric]
# @param delimiter [String] delimiter (comma by default)
# @return [String] number with delimiter
def number_with_delimiter(number)
def number_with_delimiter(number, delimiter = ',')
return '' unless number

parts = number.to_s.to_str.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, '\1,')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
parts.join('.')
end

Expand Down
32 changes: 24 additions & 8 deletions lib/karafka/web/ui/pro/views/consumers/_counters.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,56 @@
<div class="col-sm-12">
<ul class="list-unstyled row text-center mb-0 mt-0">
<li class="col-sm">
<div class="count mb-1"><%= @counters.messages %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.messages, ' ' %>
</div>
<div class="desc">Messages</div>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.batches %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.batches, ' ' %>
</div>
<div class="desc">Batches</div>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.lag_stored %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.lag_stored, ' ' %>
</div>
<div class="desc">Lag stored</div>
</li>
<li class="col-sm">
<a href="<%= root_path('jobs') %>">
<div class="count mb-1"><%= @counters.busy %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.busy, ' ' %>
</div>
<div class="desc">Busy</div>
</a>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.enqueued %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.enqueued, ' ' %>
</div>
<div class="desc">Enqueued</div>
</li>
<li class="col-sm">
<a href="<%= root_path('errors') %>">
<div class="count mb-1"><%= @counters.errors %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.errors, ' ' %>
</div>
<div class="desc">Errors</div>
</a>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.retries %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.retries, ' ' %>
</div>
<div class="desc">Retries</div>
</li>
<li class="col-sm">
<a href="<%= root_path('dlq') %>">
<div class="count mb-1"><%= @counters.dead %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.dead, ' ' %>
</div>
<div class="desc">Dead</div>
</a>
</li>
Expand Down
28 changes: 21 additions & 7 deletions lib/karafka/web/ui/views/consumers/_counters.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,49 @@
<div class="col-sm-12">
<ul class="list-unstyled row text-center mb-0 mt-0">
<li class="col-sm">
<div class="count mb-1"><%= @counters.messages %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.messages, ' ' %>
</div>
<div class="desc">Messages</div>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.batches %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.batches, ' ' %>
</div>
<div class="desc">Batches</div>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.lag_stored %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.lag_stored, ' ' %>
</div>
<div class="desc">Lag stored</div>
</li>
<li class="col-sm">
<a href="<%= root_path('jobs') %>">
<div class="count mb-1"><%= @counters.busy %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.busy, ' ' %>
</div>
<div class="desc">Busy</div>
</a>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.enqueued %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.enqueued, ' ' %>
</div>
<div class="desc">Enqueued</div>
</li>
<li class="col-sm">
<a href="<%= root_path('errors') %>">
<div class="count mb-1"><%= @counters.errors %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.errors, ' ' %>
</div>
<div class="desc">Errors</div>
</a>
</li>
<li class="col-sm">
<div class="count mb-1"><%= @counters.retries %></div>
<div class="count mb-1">
<%= number_with_delimiter @counters.retries, ' ' %>
</div>
<div class="desc">Retries</div>
</li>
</ul>
Expand Down

0 comments on commit 9bffcc8

Please sign in to comment.