Checking Virtual Machine Resource Allocations with Libvirt



Published: 2018-12-28 17:40:41 +0000
Categories: BASH,

Language

BASH

Description

Occasionally you find you need to allocate more resources to a VM, but have lost track of what's actually been allocated on the KVM host system.

Checking RAM and CPU allocations with libvirt/virsh is relatively straightforward. This documentation provides various oneliners to dump out allocations for the VMs on a host

Snippet


# List RAM Allocations for all *running* machines

virsh list | awk '{print $2}' | egrep -v -e '^$|^-|^Name$' | while read vm; do mem=$(virsh dominfo ${vm} | grep "Max memory" | awk '{print $3,$4}'); echo "$vm ${mem}"; done

# List RAM allocations for all machines

virsh list --all | awk '{print $2}' | egrep -v -e '^$|^-|^Name$' | while read vm; do mem=$(virsh dominfo ${vm} | grep "Max memory" | awk '{print $3,$4}'); echo "$vm ${mem}"; done

# List total allocation vs Host RAM for all *running* machines

virsh list | awk '{print $2}' | egrep -v -e '^$|^-|^Name$' | while read vm; do mem=$(virsh dominfo ${vm} | grep "Max memory" | awk '{print $3}'); echo "$mem"; done | awk 'BEGIN{a=0}{a=a+$1}END{print a}'; grep "MemTotal" /proc/meminfo

# List CPU allocations for all *running* machines

virsh list | awk '{print $2}' | egrep -v -e '^$|^-|^Name$' | while read vm; do cnt=$(virsh dominfo ${vm} | grep "CPU.s" | awk '{print $2}'); echo "$vm $cnt"; done 

# List total allocated CPUs vs host logical cores

virsh list | awk '{print $2}' | egrep -v -e '^$|^-|^Name$' | while read vm; do virsh dominfo ${vm} | grep "CPU.s"; done | awk 'BEGIN {a=0;} {a=a+$2;} END {print a;}'; egrep "^processor" /proc/cpuinfo | wc -l 

Requires

Keywords

libvirt, virsh, Virtual Machine, VM, Resources, dominfo, allocations,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter