Avoid crashing VM stats thread if domain migrated

This commit is contained in:
Joshua Boniface 2020-06-10 17:10:46 -04:00
parent 2967c97f1a
commit 5871380e1b

View File

@ -1326,22 +1326,27 @@ def collect_vm_stats(queue):
# Get statistics from any running VMs # Get statistics from any running VMs
for domain in running_domains: for domain in running_domains:
# Get basic information about the VM try:
tree = ElementTree.fromstring(domain.XMLDesc()) # Get basic information about the VM
domain_uuid = domain.UUIDString() tree = ElementTree.fromstring(domain.XMLDesc())
domain_name = domain.name() domain_uuid = domain.UUIDString()
domain_name = domain.name()
# Get all the raw information about the VM
if debug:
print("Getting general statistics for VM {}".format(domain_name))
domain_state, domain_maxmem, domain_mem, domain_vcpus, domain_cputime = domain.info()
domain_memory_stats = domain.memoryStats()
domain_cpu_stats = domain.getCPUStats(True)[0]
except Exception as e:
if debug:
print("Failed getting VM information for {}: {}".format(domain_name, e))
continue
# Ensure VM is present in the domain_list # Ensure VM is present in the domain_list
if domain_uuid not in this_node.domain_list: if domain_uuid not in this_node.domain_list:
this_node.domain_list.append(domain_uuid) this_node.domain_list.append(domain_uuid)
# Get all the raw information about the VM
if debug:
print("Getting general statistics for VM {}".format(domain_name))
domain_state, domain_maxmem, domain_mem, domain_vcpus, domain_cputime = domain.info()
domain_memory_stats = domain.memoryStats()
domain_cpu_stats = domain.getCPUStats(True)[0]
if debug: if debug:
print("Getting disk statistics for VM {}".format(domain_name)) print("Getting disk statistics for VM {}".format(domain_name))
domain_disk_stats = [] domain_disk_stats = []