When you are working with VMs, the hierarchy of needs tends to be Memory, Storage, Network, CPU. You can never have too much RAM when you are talking about a VM server. Since you usually consume all of your memory first, it’s nice to have a little one liner that lets you know how much memory you have allocated to VMs, and using the VirtualBox command line, this does exactly that. You’ll note that this isn’t my best work, but it’s quick and I’m not worried about all of the forking because we’re only talking about a dozen or so lines at most. Feel free to add tweaks in the comments if you can pretty it up!
VBoxManage list -l runningvms |grep Memory | awk {‘print $3′} | awk -F”MB” {‘print $1′} | echo `sed ‘s/$/+/’` | sed ‘s/+$//g’ | bc
Or this one is a little fancier and takes the total memory installed in the system, subtracts the VM memory in use +512 for the host and gives you the total physical RAM left for VM usage
VM=`VBoxManage list -l runningvms |grep Memory | awk {‘print $3′} | awk -F”MB” {‘print $1′} | echo \`sed ‘s/$/+/’\` | sed ‘s/+$//g’ | bc`; MEM=`grep MemTotal /proc/meminfo | awk {‘print $2′} | sed ‘s/$/ \/ 1024/g’|bc` >/dev/null; echo “$MEM – $VM – 512″ | bc -l