kvmstats: Utiliser domstats pour récupérer infos
All checks were successful
gitea/ansible-roles/pipeline/head This commit looks good
All checks were successful
gitea/ansible-roles/pipeline/head This commit looks good
Remplacer les multiples commandes virsh par une seule commande virsh domstats. La sortie est filtrée par une commande awk. Certains hyperviseurs ne savent pas lister les informations d’un volume RBD (Ceph) avec domblkinfo. Il semble que domstats fonctionne mieux pour ça et peut donner toutes les informations de toute façon.
This commit is contained in:
parent
8b26f2f491
commit
058753bcfe
|
@ -42,25 +42,34 @@ error () {
|
|||
main() {
|
||||
for VM in $(virsh list --name --all | sed '/^$/d' | sort)
|
||||
do
|
||||
echo "$VM"
|
||||
|
||||
# cpu
|
||||
virsh vcpucount --current "$VM"
|
||||
|
||||
# mem
|
||||
# libvirt stores memory in KiB, POW must be lowered by 1
|
||||
virsh dommemstat "$VM" 2>/dev/null | awk 'BEGIN{ret=1}$1~/^actual$/{print $2 / '$((POW / 1024))';ret=0}END{exit ret}' ||
|
||||
virsh dumpxml "$VM" | awk -F'[<>]' '$2~/^memory unit/{print $3/'$((POW / 1024))'}'
|
||||
|
||||
# disk
|
||||
for BLK in $(virsh domblklist "$VM" | sed '1,2d;/-$/d;/^$/d' | awk '{print $1}')
|
||||
do
|
||||
virsh domblkinfo "$VM" "$BLK" 2>/dev/null
|
||||
done | awk '/Physical:/ { size += $2 } END { print int(size / '${POW}') }'
|
||||
|
||||
# state
|
||||
virsh domstate "$VM" | grep -q '^running$' && echo yes || echo no
|
||||
done | xargs -n5 | {
|
||||
printf '%s ' "${VM}"
|
||||
virsh domstats "${VM}" | awk '
|
||||
BEGIN {
|
||||
FS = "="
|
||||
}
|
||||
/vcpu\.current/ {
|
||||
vcpu = $2
|
||||
}
|
||||
/balloon\.current/ {
|
||||
mem = $2
|
||||
}
|
||||
/balloon\.maximum/ {
|
||||
if (!mem)
|
||||
mem = $2
|
||||
}
|
||||
/block\.[0-9]+\.physical/ {
|
||||
disksize += $2
|
||||
}
|
||||
/state\.state/ {
|
||||
if ($2 == 1)
|
||||
running = "yes"
|
||||
else
|
||||
running = "no"
|
||||
}
|
||||
END {
|
||||
print vcpu, mem / 1024 ^ 2, disksize / 1024 ^ 3, running
|
||||
}'
|
||||
done | {
|
||||
echo vm vcpu ram disk running
|
||||
awk '{ print } /yes$/ { vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }'
|
||||
test "$SHOW_AVAIL" && {
|
||||
|
|
Loading…
Reference in a new issue