| tags:bash linux script xen categories:Tech

Xen Free Memory Bash Script

This probably isn’t 100% accurate, but it gets you in the ballpark:

total_memory=$(xm info | grep total_memory | awk '{print $3}')
used_memory=$(xm list | grep -v VCPU | awk '{SUM += $3} END {print SUM}')

echo -e 'Total Memory:\t'$total_memory'MB ('$((total_memory/1024))'GB)'
echo -e 'Memory Used:\t'$used_memory'MB ('$((used_memory/1024))'GB)'
echo -e 'Remaining:\t'$remaining'MB ('$((remaining/1024))'GB)'

Basically pulls total memory from ‘xm info’ and sums up allocated memory from ‘xm list’, then subtracts and prints out how much you’ve got available to allocate to new VMs.