Skip to content

Commit 2ececbf

Browse files
GutoVeroneziDaniel Augusto Veronezi Salvadorsureshanaparti
authored
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 <daniel@scclouds.com.br> Co-authored-by: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com>
1 parent 85e4abf commit 2ececbf

File tree

1 file changed

+7
-4
lines changed
  • plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux

1 file changed

+7
-4
lines changed

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class KVMHostInfo {
4242
private long overCommitMemory;
4343
private List<String> capabilities = new ArrayList<>();
4444

45+
private static String cpuInfoMaxFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
46+
4547
public KVMHostInfo(long reservedMemory, long overCommitMemory) {
4648
this.reservedMemory = reservedMemory;
4749
this.overCommitMemory = overCommitMemory;
@@ -78,11 +80,12 @@ public List<String> getCapabilities() {
7880
}
7981

8082
protected static long getCpuSpeed(final NodeInfo nodeInfo) {
81-
try (final Reader reader = new FileReader(
82-
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")) {
83-
return Long.parseLong(IOUtils.toString(reader).trim()) / 1000;
83+
try (Reader reader = new FileReader(cpuInfoMaxFreqFileName)) {
84+
Long cpuInfoMaxFreq = Long.parseLong(IOUtils.toString(reader).trim());
85+
LOGGER.info(String.format("Retrieved value [%s] from file [%s]. This corresponds to a CPU speed of [%s] MHz.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000));
86+
return cpuInfoMaxFreq / 1000;
8487
} catch (IOException | NumberFormatException e) {
85-
LOGGER.info("Could not read cpuinfo_max_freq, falling back on libvirt");
88+
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);
8689
return nodeInfo.mhz;
8790
}
8891
}

0 commit comments

Comments
 (0)