Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active June 23, 2021 19:37
Show Gist options
  • Save ttscoff/f699c5ff90c5ac81ccea25cae7d39b6f to your computer and use it in GitHub Desktop.
Save ttscoff/f699c5ff90c5ac81ccea25cae7d39b6f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# frozen_string_literal: true
chart_width = 20
cores = `sysctl -n hw.ncpu`.to_i
loads = `sysctl -n vm.loadavg`.split(/ /)[1..3]
unit = (chart_width.to_f / 100)
chart = Array.new(chart_width, '░')
fills = %w[▒ ▓ █]
loads.reverse.each_with_index do |ld, idx|
chart.fill(fills[idx], 0, (unit * ((ld.to_f / cores) * 100)).to_i)
end
print chart.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment