public double getMemoryPercentage() throws LibvirtException {
double memory = connection.nodeInfo().memory;
double usedMemory = 0;
for (int id : connection.listDomains()) {
Domain domain = connection.domainLookupByID(id);
if (domain != null) {
usedMemory += domain.getInfo().memory;
domain.free();
}
}
return usedMemory / memory;
}