Last active
August 29, 2015 14:04
-
-
Save snipsnipsnip/66bd8348dba6425c0792 to your computer and use it in GitHub Desktop.
lvbar.rb is a `pvs` wrapper that shows allocation status of LVM logical volumes in bar chart
This file contains 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
$ sudo ruby lvbar.rb | |
/dev/sda0 | |
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] | |
a: vg_foo/lv_bar (54%) | |
b: (unallocated) (46%) | |
/dev/sda1 | |
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] | |
a: vg_foo/lv_baz (100%) | |
/dev/sda2 | |
[aaaaaaaaaaaaaaa|bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|c] | |
a: vg_sys/lv_root (22%) | |
b: vg_sys/lv_home (77%) | |
c: vg_sys/lv_swap (2%) |
This file contains 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 | |
Row = Struct.new(:pv_name, :pv_pe_count, :vg_name, :lv_name, :pvseg_start, :pvseg_size) do | |
def name | |
lv_name.empty? ? nil : "#{vg_name}/#{lv_name}" | |
end | |
def start_ratio | |
Rational(pvseg_start, pv_pe_count) | |
end | |
def size_ratio | |
Rational(pvseg_size, pv_pe_count) | |
end | |
end | |
table = `pvs --noheadings --separator=: --options=#{PVS.members.join(',')}`.lines.map {|x| PVS.new *x.strip.split(/:/) } | |
pvs = table.group_by {|row| row.pv_name } | |
pvs.each do |pv_name, segments| | |
puts pv_name | |
puts " [#{segments.each_with_index.map {|row, i| (i + 10).to_s(36) * ([(70 * row.size_ratio).to_i, 1].max) }.join('|')}]" | |
segments.each_with_index do |row, i| | |
puts " #{(i + 10).to_s(36)}: #{row.name || '(unallocated)'} (#{(row.size_ratio * 100).round}%)" | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LVMの配置の具合を棒グラフでCUIで見たかったのでやっつけた。