def collect(self):
        if libvirt is None:
            self.log.error('Unable to import either libvirt')
            return {}
        #Open a restricted (non-root) connection to the hypervisor
        conn = libvirt.openReadOnly(None)
        #Get hardware info
        conninfo = conn.getInfo()
        #Initialize variables
        memallocated = 0
        coresallocated = 0
        totalcores = 0
        results = {}
        domIds = conn.listDomainsID()
        if 0 in domIds:
        #Total cores
            domU = conn.lookupByID(0)
            totalcores = domU.info()[3]
        #Free Space
        s = os.statvfs('/')
        freeSpace = (s.f_bavail * s.f_frsize) / 1024
        #Calculate allocated memory and cores
        for i in domIds:
            # Ignore 0
            if i == 0:
                continue
            domU = conn.lookupByID(i)
            dominfo = domU.info()
            memallocated += dominfo[2]
            if i > 0:
                coresallocated += dominfo[3]
        results = {
            'InstalledMem': conninfo[1],
            'MemAllocated': memallocated / 1024,
            'MemFree': conninfo[1] - (memallocated / 1024),
            'AllocatedCores': coresallocated,
            'DiskFree': freeSpace,
            'TotalCores': totalcores,
            'FreeCores': (totalcores - coresallocated)
        }
        for k in results.keys():
            self.publish(k, results[k], 0)
Collect libvirt data
dataset/ETHPy150Open BrightcoveOS/Diamond/src/collectors/xen_collector/xen_collector.py/XENCollector.collect