Last active
June 23, 2021 19:37
-
-
Save ttscoff/f699c5ff90c5ac81ccea25cae7d39b6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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