Handle VM disk/network stats gathering exceptions
This commit is contained in:
parent
73c96d1e93
commit
1b6d10e03a
|
@ -429,42 +429,58 @@ 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 = []
|
||||||
for disk in tree.findall('devices/disk'):
|
try:
|
||||||
disk_name = disk.find('source').get('name')
|
for disk in tree.findall('devices/disk'):
|
||||||
if not disk_name:
|
disk_name = disk.find('source').get('name')
|
||||||
disk_name = disk.find('source').get('file')
|
if not disk_name:
|
||||||
disk_stats = domain.blockStats(disk.find('target').get('dev'))
|
disk_name = disk.find('source').get('file')
|
||||||
domain_disk_stats.append({
|
disk_stats = domain.blockStats(disk.find('target').get('dev'))
|
||||||
"name": disk_name,
|
domain_disk_stats.append({
|
||||||
"rd_req": disk_stats[0],
|
"name": disk_name,
|
||||||
"rd_bytes": disk_stats[1],
|
"rd_req": disk_stats[0],
|
||||||
"wr_req": disk_stats[2],
|
"rd_bytes": disk_stats[1],
|
||||||
"wr_bytes": disk_stats[3],
|
"wr_req": disk_stats[2],
|
||||||
"err": disk_stats[4]
|
"wr_bytes": disk_stats[3],
|
||||||
})
|
"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 = []
|
||||||
for interface in tree.findall('devices/interface'):
|
try:
|
||||||
interface_type = interface.get('type')
|
for interface in tree.findall('devices/interface'):
|
||||||
if interface_type not in ['bridge']:
|
interface_type = interface.get('type')
|
||||||
continue
|
if interface_type not in ['bridge']:
|
||||||
interface_name = interface.find('target').get('dev')
|
continue
|
||||||
interface_bridge = interface.find('source').get('bridge')
|
interface_name = interface.find('target').get('dev')
|
||||||
interface_stats = domain.interfaceStats(interface_name)
|
interface_bridge = interface.find('source').get('bridge')
|
||||||
domain_network_stats.append({
|
interface_stats = domain.interfaceStats(interface_name)
|
||||||
"name": interface_name,
|
domain_network_stats.append({
|
||||||
"bridge": interface_bridge,
|
"name": interface_name,
|
||||||
"rd_bytes": interface_stats[0],
|
"bridge": interface_bridge,
|
||||||
"rd_packets": interface_stats[1],
|
"rd_bytes": interface_stats[0],
|
||||||
"rd_errors": interface_stats[2],
|
"rd_packets": interface_stats[1],
|
||||||
"rd_drops": interface_stats[3],
|
"rd_errors": interface_stats[2],
|
||||||
"wr_bytes": interface_stats[4],
|
"rd_drops": interface_stats[3],
|
||||||
"wr_packets": interface_stats[5],
|
"wr_bytes": interface_stats[4],
|
||||||
"wr_errors": interface_stats[6],
|
"wr_packets": interface_stats[5],
|
||||||
"wr_drops": interface_stats[7]
|
"wr_errors": interface_stats[6],
|
||||||
})
|
"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()
|
||||||
|
|
Loading…
Reference in New Issue