Skip to content

Instantly share code, notes, and snippets.

@ziggythehamster
Last active July 1, 2016 03:25
Show Gist options
  • Save ziggythehamster/fb9ce120387befed7871370ed0365cd5 to your computer and use it in GitHub Desktop.
Save ziggythehamster/fb9ce120387befed7871370ed0365cd5 to your computer and use it in GitHub Desktop.
sidekiq_monitor.rb
# box drawing characters
DUL = "\u2554" # double, upper left
DUR = "\u2557" # double, upper right
DHO = "\u2550" # double, horizontal
DVR = "\u2551" # double, vertical
DLL = "\u255A" # double, lower left
DLR = "\u255D" # double, lower right
SHO = "\u2500" # single, horizontal
SVR = "\u2502" # single, vertical
SXR = "\u253C" # single, cross
loop do
ENV['TERM'] = 'xterm-256color'
system('clear')
header = DUL + " #{Time.current.iso8601} ".center(78, DHO) + DUR
puts Rainbow(header).color(:white).bright
puts Rainbow(DVR + " QUEUE NAME " + SVR + " QUEUE SIZE" + (' ' * 40) + DVR).color(:white).bright
puts Rainbow(DVR + (SHO * 26) + SXR + (SHO * 51) + DVR).color(:white).bright
Sidekiq::Queue.all.map do |q|
puts Rainbow("#{DVR} ").color(:white).bright + sprintf("%-25s", q.name) + Rainbow("#{SVR} ").color(:white).bright + sprintf("%-50d", q.size) + Rainbow(DVR).color(:white).bright
end
puts Rainbow("#{DLL}#{DHO * 78}#{DLR}").color(:white).bright
stats = Sidekiq::Stats.new
puts ""
header = DUL + " SIDEKIQ STATS ".center(78, DHO) + DUR
puts Rainbow(header).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Total Processed " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.processed) + Rainbow(DVR).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Total Failed " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.failed) + Rainbow(DVR).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Retry Size " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.retry_size) + Rainbow(DVR).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Processes Size " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.processes_size) + Rainbow(DVR).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Workers Size " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.workers_size) + Rainbow(DVR).color(:white).bright
puts Rainbow(DVR).color(:white).bright + " Enqueued " + Rainbow(SVR).color(:white).bright + sprintf(" %-50d", stats.enqueued) + Rainbow(DVR).color(:white).bright
puts Rainbow("#{DLL}#{DHO * 78}#{DLR}").color(:white).bright
puts ""
# batch stats
puts Rainbow(DUL + (DHO * 214) + DUR).color(:white).bright
puts Rainbow("#{DVR} BATCH DESCRIPTION" + (' ' * 48) + SVR + " BID" + (' ' * 12) + SVR + " PROGRESS" + (' ' * 121) + DVR).bright
puts Rainbow(DVR + (SHO * 66) + SXR + (SHO * 16) + SXR + (SHO * 130) + DVR).color(:white).bright
Sidekiq::BatchSet.new.each do |b|
total = b.total
pending = b.pending
completed = b.total - b.pending
if total > 0
progress = completed.to_f / total.to_f
flat_prog = (progress * 100).floor
if pending == 0
color = :green
elsif pending == total
color = :red
else
color = :yellow
end
progbar_completed = Rainbow("\u2588" * flat_prog).color(color)
pbar = "#{progbar_completed}#{Rainbow("\u2591" * (100 - flat_prog)).color(color)} #{completed}/#{total}"
pbar_col_width = 146
if b.failures > 0
failures = "failures"
failures = "failure" if b.failures == 1
pbar += Rainbow(" (#{b.failures} #{failures})").color(:red)
pbar_col_width = 155
end
else
pbar_col_width = 137
pbar = Rainbow("total=#{total}, pending=#{pending}").color(:magenta)
end
if b.description.nil?
description = Rainbow('<no batch description>' + (' ' * 42)).magenta
else
description = b.description
end
puts Rainbow(DVR).color(:white).bright + sprintf(" %-64s ", description) + Rainbow(SVR).color(:white).bright + sprintf(" %-s ", b.bid) + Rainbow(SVR).color(:white).bright + sprintf(" %-#{pbar_col_width}s ", pbar) + Rainbow(DVR).color(:white).bright
end
puts Rainbow(DLL + (DHO * 214) + DLR).color(:white).bright
sleep 2
end
@ziggythehamster
Copy link
Author

If someone wants to fork this and make it something other than a horrible hack, please do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment