Properly handle exceptions getting VM stats

This commit is contained in:
Joshua Boniface 2021-08-19 12:36:31 -04:00
parent 074664d4c1
commit 180f0445ac
1 changed files with 41 additions and 37 deletions

View File

@ -1675,11 +1675,7 @@ def collect_vm_stats(queue):
domain_memory_stats = domain.memoryStats() domain_memory_stats = domain.memoryStats()
domain_cpu_stats = domain.getCPUStats(True)[0] domain_cpu_stats = domain.getCPUStats(True)[0]
except Exception as e: except Exception as e:
if debug: logger.out("Failed getting VM information for {}: {}".format(domain.name(), e), state='w', prefix='vm-thread')
try:
logger.out("Failed getting VM information for {}: {}".format(domain.name(), e), state='d', prefix='vm-thread')
except Exception:
pass
continue continue
# Ensure VM is present in the domain_list # Ensure VM is present in the domain_list
@ -1689,6 +1685,7 @@ def collect_vm_stats(queue):
if debug: if debug:
logger.out("Getting disk statistics for VM {}".format(domain_name), state='d', prefix='vm-thread') logger.out("Getting disk statistics for VM {}".format(domain_name), state='d', prefix='vm-thread')
domain_disk_stats = [] domain_disk_stats = []
try:
for disk in tree.findall('devices/disk'): for disk in tree.findall('devices/disk'):
disk_name = disk.find('source').get('name') disk_name = disk.find('source').get('name')
if not disk_name: if not disk_name:
@ -1702,10 +1699,14 @@ def collect_vm_stats(queue):
"wr_bytes": disk_stats[3], "wr_bytes": disk_stats[3],
"err": disk_stats[4] "err": disk_stats[4]
}) })
except Exception as e:
logger.out("Failed to get disk stats for VM {}: {}".format(domain_name, e), state='w', prefix='vm-thread')
continue
if debug: if debug:
logger.out("Getting network statistics for VM {}".format(domain_name), state='d', prefix='vm-thread') logger.out("Getting network statistics for VM {}".format(domain_name), state='d', prefix='vm-thread')
domain_network_stats = [] domain_network_stats = []
try:
for interface in tree.findall('devices/interface'): for interface in tree.findall('devices/interface'):
interface_type = interface.get('type') interface_type = interface.get('type')
if interface_type not in ['bridge']: if interface_type not in ['bridge']:
@ -1725,6 +1726,9 @@ def collect_vm_stats(queue):
"wr_errors": interface_stats[6], "wr_errors": interface_stats[6],
"wr_drops": interface_stats[7] "wr_drops": interface_stats[7]
}) })
except Exception as e:
logger.out("Failed to get network stats for VM {}: {}".format(domain_name, e), state='w', prefix='vm-thread')
continue
# Create the final dictionary # Create the final dictionary
domain_stats = { domain_stats = {