Created
September 21, 2011 09:37
-
-
Save jonyesno/1231663 to your computer and use it in GitHub Desktop.
Total up KVM / qemu VM sizes from ps(1) output
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 | |
sizes = [] | |
IO.popen("ps waux") do |pipe| | |
pipe.each do |line| | |
next unless line.match(/qemu/) | |
vm = line.match(%r{qemu/(\w+)\.monitor})[1] | |
bits = line.split(/\s+/) | |
vsz, rss = bits[4,5] | |
sizes.push({ :vm => vm, :vsz => vsz, :rss => rss }) | |
end | |
end | |
sizes.each do |size| | |
puts "#{size[:vm].ljust(32)} rss: #{size[:rss].rjust(16)} vsz: #{size[:vsz].rjust(16)}" | |
end | |
rss = sizes.inject(0) { |t,n| t+= n[:rss].to_i } / 1024 / 1024 | |
vsz = sizes.inject(0) { |t,n| t+= n[:vsz].to_i } / 1024 / 1024 | |
puts "total".ljust(32) + " rss: #{rss.to_s.rjust(13)} GB vsz: #{vsz.to_s.rjust(13)} GB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment