RAM
---
cloudflared_default = 1,024 MiB (Actual: 1,000 MiB)
sonarqube_default = 8,192 MiB (Actual: 5,778 MiB)
coder_default = 16,384 MiB (Actual: 6,268 MiB)
Total Allocated: 25,600 MiB
Total Actual Used: 13,046 MiB
CPU(s)
------
cloudflared_default = 1 cpu(s)
sonarqube_default = 4 cpu(s)
coder_default = 4 cpu(s)
Total: 9 CPU(s)
Created
January 16, 2025 17:00
-
-
Save tranphuquy19/750fdb86def902b4b0adf5e2009203b4 to your computer and use it in GitHub Desktop.
Show Memory and CPU usage of libvirt vms
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
#!/bin/bash | |
# | |
# RAM | |
# | |
echo "RAM" | |
echo "---" | |
SUM=0 | |
SUM_ACTUAL=0 | |
while read vm | |
do | |
if [ ! -z "$vm" ]; then | |
MAX_MEM=$(($(virsh dominfo $vm | grep "Max memory" | cut -f 7 -d " ") / 1024)) | |
ACTUAL_MEM=$(virsh dommemstat $vm 2>/dev/null | grep rss | awk '{print $2/1024}') | |
if [ ! -z "$ACTUAL_MEM" ]; then | |
printf "%-25s = %'.0f MiB (Actual: %'.0f MiB)\n" $vm $MAX_MEM $ACTUAL_MEM | |
SUM=$((SUM + MAX_MEM)) | |
SUM_ACTUAL=$(awk "BEGIN {print $SUM_ACTUAL + $ACTUAL_MEM}") | |
else | |
printf "%-25s = %'.0f MiB (Offline)\n" $vm $MAX_MEM | |
SUM=$((SUM + MAX_MEM)) | |
fi | |
fi | |
done < <(virsh list --all --name) | |
printf "\nTotal Allocated: %'.0f MiB\n" $SUM | |
printf "Total Actual Used: %'.0f MiB\n\n" $SUM_ACTUAL | |
# | |
# 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