Add -u option
This option controls the unit factor of the RAM.
This commit is contained in:
parent
42226c7817
commit
1dc0c0299e
32
kvmstats.sh
32
kvmstats.sh
|
@ -1,5 +1,35 @@
|
|||
#!/bin/sh
|
||||
|
||||
usage () {
|
||||
echo 'usage: kvmstats.sh [-u M|G]'
|
||||
exit 1
|
||||
}
|
||||
|
||||
POW=$(echo 1024 ^ 1 | bc)
|
||||
while echo $1 | grep -q '^-[[:alnum:]]'
|
||||
do
|
||||
case $1 in
|
||||
'-u')
|
||||
case $2 in
|
||||
'M')
|
||||
POW=$(echo 1024 ^ 2 | bc)
|
||||
;;
|
||||
'G')
|
||||
POW=$(echo 1024 ^ 3 | bc)
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# since libvirt seems to store memoy in KiB, POW must be lowered by 1
|
||||
POW=$(expr $POW / 1024)
|
||||
|
||||
for DEP in hxselect lvs tempfile
|
||||
do
|
||||
if [ -z "$(which $DEP)" ]
|
||||
|
@ -14,7 +44,7 @@ TMPFILE=$(tempfile)
|
|||
for VM in $(virsh list --all --name)
|
||||
do
|
||||
VCPU=$(hxselect -c 'domain vcpu' </etc/libvirt/qemu/$VM.xml)
|
||||
RAM=$(hxselect -c 'domain memory' </etc/libvirt/qemu/$VM.xml)
|
||||
RAM=$(expr $(hxselect -c 'domain memory' </etc/libvirt/qemu/$VM.xml) / $POW)
|
||||
for DEV in $(hxselect -s'\n' 'domain devices disk[device=disk] source' </etc/libvirt/qemu/$VM.xml | cut -d\" -f2)
|
||||
do
|
||||
case $DEV in
|
||||
|
|
Loading…
Reference in a new issue