RAM
---
vm-1 = 1,024 MiB
vm-2 = 2,048 MiB
Total: 3,072 MiB
CPU(s)
------
vm-1 = 4 cpu(s)
vm-2 = 5 cpu(s)
Total: 9 CPU(s)
Last active
April 9, 2024 13:38
-
-
Save 0x3333/1d12b70034f97435bcc8ee41971a79fc to your computer and use it in GitHub Desktop.
Show Memory and CPU usage of kvm vms
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
#!/bin/bash | |
# | |
# RAM | |
# | |
echo "RAM" | |
echo "---" | |
SUM=0 | |
while read vm | |
do | |
if [ ! -z "$vm" ]; then | |
USED=$(($(virsh dominfo $vm | grep "Max memory" | cut -f 7 -d " ") / 1024)) | |
printf "%-25s = %'.0f MiB\n" $vm $USED | |
SUM=$((SUM + USED)) | |
fi | |
done < <(virsh list --all --name) | |
printf "\nTotal: %'.0f MiB\n\n" $SUM | |
# | |
# CPUs | |
# | |
echo "CPU(s)" | |
echo "------" | |
SUM=0 | |
while read vm | |
do | |
if [ ! -z "$vm" ]; then | |
USED=$(virsh dominfo $vm | grep "CPU(s)" | cut -f 10 -d " ") | |
printf "%-25s = %'.0f cpu(s)\n" $vm $USED | |
SUM=$((SUM + USED)) | |
fi | |
done < <(virsh list --all --name) | |
printf "\nTotal: %'.0f CPU(s)\n" $SUM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replaced cut with awk and added allocated storage. Plus count storage if multiple disks.