Skip to content

Commit bde80f1

Browse files
authored
Fix NPE in management server logs due to /proc/cpuinfo output (#7765)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 6dd2ce8 commit bde80f1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,16 @@ private double[] getCpuLoads() {
974974
private double getSystemCpuCyclesTotal() {
975975
String cpucaps = Script.runSimpleBashScript("cat /proc/cpuinfo | grep \"cpu MHz\" | grep \"cpu MHz\" | cut -f 2 -d : | tr -d ' '| tr '\\n' \" \"");
976976
double totalcpucap = 0;
977-
for (String cpucap : cpucaps.split(" ")) {
978-
totalcpucap += Double.parseDouble(cpucap);
977+
if (StringUtils.isEmpty(cpucaps)) {
978+
String totalCpus = Script.runSimpleBashScript("nproc --all| tr '\\n' \" \"");
979+
String maxCpuSpeed = Script.runSimpleBashScript("lscpu | egrep 'CPU max MHz' | head -1 | cut -f 2 -d : | tr -d ' '| tr '\\n' \" \"");
980+
if (StringUtils.isNotEmpty(totalCpus) && StringUtils.isNotEmpty(maxCpuSpeed)) {
981+
totalcpucap = Double.parseDouble(totalCpus) * Double.parseDouble(maxCpuSpeed);
982+
}
983+
} else {
984+
for (String cpucap : cpucaps.split(" ")) {
985+
totalcpucap += Double.parseDouble(cpucap);
986+
}
979987
}
980988
return totalcpucap;
981989
}

0 commit comments

Comments
 (0)