How to measure boot time of a VM from host machine

kvm-virtualizationlibvirtqemuvirtualization

On both Guest machine and host machine, I am using Ubuntu 12.04. As a hypervisor I am using KVM. I want to perform some experiments related to boot-storm and I have created all other scripts to create VM, delete VM and start VM. But I don't know how to measure boot time for each VM.

Though not necessary but it will be good if the boot time has one to one mapping to VM in some sense, by name or by mac address etc.

Boot time: I want to do ssh from host and when its successful I will consider that the VM has been booted up successfully.

The solution should be scalable as I want to perform experiment for 100-150 VMs.

Problems:

1) How to get the IP address of a guest VM from Host machine ?

2) Mapping of Domainname-> IP

3) Mapping of IP -> Boot time

Best Answer

Here is an example how you can test if a machine is online using ping:

#!/bin/bash
# test-online.sh
ret=1
while [ $ret != 0 ]
do
  ping -c 1 $1 2>/dev/null
  ret=$?
done
exit 0

You can adapt this to use ssh by replacing the ping line with something like ssh $1 "echo", assuming you can connect to the machine without a password.

Using the above script (let's call it test-online.sh), you can start the machine and then measure the time using GNU time (the first argument of this script is the machine name):

#!/bin/bash
# start-and-time.sh
start-vm $1
/usr/bin/time -f "%E" ./test-online.sh $1

The output will be something like 1:23.52 which means your machine took 1 minute 23 seconds to boot.

If you want to measure the boot time of many machines, you can just call start-and-time.sh for every machine:

#!/bin/bash
mymachines=(machine1 machine2 machine3)
for machine in "${machines[@]}"
do
  echo -n "$machine "
  ./start-and-time.sh $machine &
done

which will give the following exemplary output:

machine1 1:53.23
machine2 2:42.42
machine3 0:42.42