def get_diagnostics(self, instance):

    def get_io_devices(xml_doc):
        'get the list of io devices from the xml document.'
        result = {'volumes': [], 'ifaces': []}
        try:
            doc = etree.fromstring(xml_doc)
        except Exception:
            return result
        blocks = [('./devices/disk', 'volumes'), ('./devices/interface', 'ifaces')]
        for (block, key) in blocks:
            section = doc.findall(block)
            for node in section:
                for child in node.getchildren():
                    if ((child.tag == 'target') and child.get('dev')):
                        result[key].append(child.get('dev'))
        return result
    domain = self._lookup_by_name(instance['name'])
    output = {}
    try:
        cputime = domain.vcpus()[0]
        for i in range(len(cputime)):
            output[(('cpu' + str(i)) + '_time')] = cputime[i][2]
    except libvirt.libvirtError:
        pass
    xml = domain.XMLDesc(0)
    dom_io = get_io_devices(xml)
    for guest_disk in dom_io['volumes']:
        try:
            stats = domain.blockStats(guest_disk)
            output[(guest_disk + '_read_req')] = stats[0]
            output[(guest_disk + '_read')] = stats[1]
            output[(guest_disk + '_write_req')] = stats[2]
            output[(guest_disk + '_write')] = stats[3]
            output[(guest_disk + '_errors')] = stats[4]
        except libvirt.libvirtError:
            pass
    for interface in dom_io['ifaces']:
        try:
            stats = domain.interfaceStats(interface)
            output[(interface + '_rx')] = stats[0]
            output[(interface + '_rx_packets')] = stats[1]
            output[(interface + '_rx_errors')] = stats[2]
            output[(interface + '_rx_drop')] = stats[3]
            output[(interface + '_tx')] = stats[4]
            output[(interface + '_tx_packets')] = stats[5]
            output[(interface + '_tx_errors')] = stats[6]
            output[(interface + '_tx_drop')] = stats[7]
        except libvirt.libvirtError:
            pass
    output['memory'] = domain.maxMemory()
    try:
        mem = domain.memoryStats()
        for key in mem.keys():
            output[('memory-' + key)] = mem[key]
    except (libvirt.libvirtError, AttributeError):
        pass
    return output
def get_diagnostics(self, instance):

    def get_io_devices(xml_doc):
        'get the list of io devices from the xml document.'
        result = {'volumes': [], 'ifaces': []}
        try:
            doc = etree.fromstring(xml_doc)
        except Exception:
            return result
        blocks = [('./devices/disk', 'volumes'), ('./devices/interface', 'ifaces')]
        for (block, key) in blocks:
            section = doc.findall(block)
            for node in section:
                for child in node.getchildren():
                    if ((child.tag == 'target') and child.get('dev')):
                        result[key].append(child.get('dev'))
        return result
    domain = self._lookup_by_name(instance['name'])
    output = {}
    try:
        cputime = domain.vcpus()[0]
        for i in range(len(cputime)):
            output[(('cpu' + str(i)) + '_time')] = cputime[i][2]
    except libvirt.libvirtError:
        pass
    xml = domain.XMLDesc(0)
    dom_io = get_io_devices(xml)
    for guest_disk in dom_io['volumes']:
        try:
            stats = domain.blockStats(guest_disk)
            output[(guest_disk + '_read_req')] = stats[0]
            output[(guest_disk + '_read')] = stats[1]
            output[(guest_disk + '_write_req')] = stats[2]
            output[(guest_disk + '_write')] = stats[3]
            output[(guest_disk + '_errors')] = stats[4]
        except libvirt.libvirtError:
            pass
    for interface in dom_io['ifaces']:
        try:
            stats = domain.interfaceStats(interface)
            output[(interface + '_rx')] = stats[0]
            output[(interface + '_rx_packets')] = stats[1]
            output[(interface + '_rx_errors')] = stats[2]
            output[(interface + '_rx_drop')] = stats[3]
            output[(interface + '_tx')] = stats[4]
            output[(interface + '_tx_packets')] = stats[5]
            output[(interface + '_tx_errors')] = stats[6]
            output[(interface + '_tx_drop')] = stats[7]
        except libvirt.libvirtError:
            pass
    output['memory'] = domain.maxMemory()
    try:
        mem = domain.memoryStats()
        for key in mem.keys():
            output[('memory-' + key)] = mem[key]
    except (libvirt.libvirtError, AttributeError):
        pass
    return output