From 2ececbf9942f966e9a637d758c66c073599de988 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Thu, 17 Jun 2021 04:51:30 -0300 Subject: [PATCH] kvm: Improve logs on agent start (#4958) This PR intends to improve logging on agent start to facilitate troubleshooting. Co-authored-by: Daniel Augusto Veronezi Salvador Co-authored-by: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com> --- .../apache/cloudstack/utils/linux/KVMHostInfo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index 1f28304806a..60e98f58e72 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -42,6 +42,8 @@ public class KVMHostInfo { private long overCommitMemory; private List capabilities = new ArrayList<>(); + private static String cpuInfoMaxFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; + public KVMHostInfo(long reservedMemory, long overCommitMemory) { this.reservedMemory = reservedMemory; this.overCommitMemory = overCommitMemory; @@ -78,11 +80,12 @@ public class KVMHostInfo { } protected static long getCpuSpeed(final NodeInfo nodeInfo) { - try (final Reader reader = new FileReader( - "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")) { - return Long.parseLong(IOUtils.toString(reader).trim()) / 1000; + try (Reader reader = new FileReader(cpuInfoMaxFreqFileName)) { + Long cpuInfoMaxFreq = Long.parseLong(IOUtils.toString(reader).trim()); + LOGGER.info(String.format("Retrieved value [%s] from file [%s]. This corresponds to a CPU speed of [%s] MHz.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000)); + return cpuInfoMaxFreq / 1000; } catch (IOException | NumberFormatException e) { - LOGGER.info("Could not read cpuinfo_max_freq, falling back on libvirt"); + LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e); return nodeInfo.mhz; } }