winterhazel commented on code in PR #8511:
URL: https://github.com/apache/cloudstack/pull/8511#discussion_r1473133257
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -4401,127 +4403,193 @@ protected String getDiskPathFromDiskDef(DiskDef disk)
{
return null;
}
- private class VmStats {
- long usedTime;
- long tx;
- long rx;
- long ioRead;
- long ioWrote;
- long bytesRead;
- long bytesWrote;
- Calendar timestamp;
+ private String vmToString(Domain dm) throws LibvirtException {
+ return String.format("{\"name\":\"%s\",\"uuid\":\"%s\"}",
dm.getName(), dm.getUUIDString());
}
+ /**
+ * Returns metrics for the period since this function was last called for
the specified VM.
+ * @param conn the Libvirt connection.
+ * @param vmName name of the VM.
+ * @return metrics for the period since last time this function was called
for the VM.
+ * @throws LibvirtException
+ */
public VmStatsEntry getVmStat(final Connect conn, final String vmName)
throws LibvirtException {
Domain dm = null;
try {
+ s_logger.debug(String.format("Trying to get VM with name [%s].",
vmName));
dm = getDomain(conn, vmName);
if (dm == null) {
+ s_logger.warn(String.format("Could not get VM with name
[%s].", vmName));
return null;
}
- DomainInfo info = dm.getInfo();
- final VmStatsEntry stats = new VmStatsEntry();
- stats.setNumCPUs(info.nrVirtCpu);
- stats.setEntityType("vm");
+ LibvirtExtendedVmStatsEntry newStats = getVmCurrentStats(dm);
+ LibvirtExtendedVmStatsEntry oldStats = vmStats.get(vmName);
- stats.setMemoryKBs(info.maxMem);
- stats.setTargetMemoryKBs(info.memory);
- stats.setIntFreeMemoryKBs(getMemoryFreeInKBs(dm));
+ VmStatsEntry metrics = calculateVmMetrics(dm, oldStats, newStats);
- /* get cpu utilization */
- VmStats oldStats = null;
+ String vmAsString = vmToString(dm);
+ s_logger.info(String.format("Saving stats for VM [%s].",
vmAsString));
+ vmStats.put(vmName, newStats);
+ s_logger.debug(String.format("Saved stats for VM [%s]: [%s].",
vmAsString, newStats));
Review Comment:
I think debug is the appropriate level for the second log, since it presents
information more useful for debugging purposes instead of everyday operation.
Also, it has a lot of data and the metrics collection is quite frequent, so it
can end up overwhelming the info level.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]