conn = libvirt.openReadOnly() if conn is None: raise Exception('Failed to open connection to the hypervisor') for id in conn.listDomainsID(): dom = conn.lookupByID(id) block_stats = {} block_stats = {"devices": []} for dev in common.domain_xml(dom).findall("devices/disk/target"): devname = dev.get("dev") block_stats["devices"].append(devname) stats = dom.blockStats(devname) block_stats[devname] = { "rd_req": stats[0], "rd_bytes": stats[1], "wr_req": stats[2], "wr_bytes": stats[3], "errs": stats[4] } print json.dumps({ "timestamp": common.now(), "nova": common.nova_metadata(dom), "uuid": dom.UUIDString(), "name": dom.name(), "id": dom.ID(), "block_stats": block_stats }) except Exception, e: print json.dumps({"timestamp": common.now(), "error": "%s" % e})
for dev in common.domain_xml(dom).findall("devices/disk/target"): devname = dev.get("dev") block_info["devices"].append(devname) info = dom.blockInfo(devname) block_info[devname] = { # logical size in bytes of the image # (how much storage the guest will see) "capacity": info[0], # host storage in bytes occupied by # the image (such as highest allocated # extent if there are no holes, similar to 'du') "allocation": info[1], # host physical size in bytes of the # image container (last offset, similar to 'ls') "physical": info[2] } print json.dumps(OrderedDict([ ("timestamp", common.now()), ("nova", common.nova_metadata(dom)), ("uuid", dom.UUIDString()), ("name", dom.name()), ("id", dom.ID()), ("block_info", block_info) ])) except Exception, e: print json.dumps({"timestamp": common.now(), "error": "%s" % e})
# (how much storage the guest will see) "capacity": info[0], # host storage in bytes occupied by # the image (such as highest allocated # extent if there are no holes, similar to 'du') "allocation": info[1], # host physical size in bytes of the # image container (last offset, similar to 'ls') "physical": info[2] } print json.dumps({ "timestamp": common.now(), "nova_uuid": common.nova_metadata(dom)['project']['uuid'], "nova_name": common.nova_metadata(dom)['project']['name'], "uuid": dom.UUIDString(), "name": dom.name(), "id": dom.ID(), "vda_allocation": block_info['vda']['allocation'], "vda_capacity": block_info['vda']['capacity'], "vda_physical": block_info['vda']['physical'], "hdd_allocation": block_info['hdd']['allocation'], "hdd_capacity": block_info['hdd']['capacity'], "hdd_physical": block_info['hdd']['physical'], }) except Exception, e: print json.dumps({"timestamp": common.now(), "error": "%s" % e})