Determining when a guest booted / how long it's been running

Michal Prívozník mprivozn at redhat.com
Thu Oct 1 05:21:53 UTC 2020


On 10/1/20 3:42 AM, Digimer wrote:
> Hi all,
> 
>    Is there a way to tell when a tool made a change to guest (ie: used 
> virt-manager to make a change)? Following, is there a way to check to 
> see if there are changes queued to take effect when the guest next reboots?
> 

You can listen for events. For changes to inactive XML you will get 
VIR_DOMAIN_EVENT_DEFINED+VIR_DOMAIN_EVENT_DEFINED_UPDATED lifecycle 
event (+reason) and for changes to live XML (like hotplug and hotunplug) 
you'll get DEVICE_ADDED or DEVICE_REMOVED.

But there is no API/virsh command that you could call to get the 
timestamp of last modification. You have to listen for events.

And the second question - you can dump live and inactive XML and see if 
there is any difference (modulo runtime configuration from live XML). 
The live XML should be strictly bigger than inactive XML, meaning live 
XML should be inactive XML + runtime info. But again, no API there, 
because changes to inactive XML can be done any time - libvirt keeps 
live and inactive XMLs separately.

>    If either of the above are not possible, is there a way to see when a 
> guest last booted or how long a guest has been running?

Again, if listening to evens - libvirt emits one when a guest is 
started. But I don't think we store a timestamp of start anywhere nor 
expose it through an API. Maybe there is some indirect way?

Michal




More information about the libvirt-users mailing list