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>
This commit is contained in:
Daniel Augusto Veronezi Salvador 2021-06-17 04:51:30 -03:00 committed by GitHub
parent 85e4abf522
commit 2ececbf994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -42,6 +42,8 @@ public class KVMHostInfo {
private long overCommitMemory;
private List<String> 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;
}
}