Handle VM disk/network stats gathering exceptions

This commit is contained in:
Joshua Boniface 2021-09-12 19:41:07 -04:00
parent 73c96d1e93
commit 1b6d10e03a
1 changed files with 49 additions and 33 deletions

View File

@ -429,6 +429,7 @@ def collect_vm_stats(logger, config, zkhandler, this_node, 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:
@ -442,10 +443,18 @@ def collect_vm_stats(logger, config, zkhandler, this_node, queue):
"wr_bytes": disk_stats[3], "wr_bytes": disk_stats[3],
"err": disk_stats[4] "err": disk_stats[4]
}) })
except Exception as e:
if debug:
try:
logger.out("Failed getting disk stats for {}: {}".format(domain.name(), e), state='d', prefix='vm-thread')
except Exception:
pass
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']:
@ -465,6 +474,13 @@ def collect_vm_stats(logger, config, zkhandler, this_node, 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:
if debug:
try:
logger.out("Failed getting network stats for {}: {}".format(domain.name(), e), state='d', prefix='vm-thread')
except Exception:
pass
continue
# Create the final dictionary # Create the final dictionary
domain_stats = { domain_stats = {
@ -488,7 +504,7 @@ def collect_vm_stats(logger, config, zkhandler, this_node, queue):
]) ])
except Exception as e: except Exception as e:
if debug: if debug:
logger.out("{}".format(e), state='d', prefix='vm-thread') logger.out("Failed to write domain statistics: {}".format(e), state='d', prefix='vm-thread')
# Close the Libvirt connection # Close the Libvirt connection
lv_conn.close() lv_conn.close()