Fix NPE in management server logs due to /proc/cpuinfo output (#7765)

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2023-07-25 08:13:33 +05:30 committed by GitHub
parent 6dd2ce86b5
commit bde80f14aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -974,8 +974,16 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
private double getSystemCpuCyclesTotal() {
String cpucaps = Script.runSimpleBashScript("cat /proc/cpuinfo | grep \"cpu MHz\" | grep \"cpu MHz\" | cut -f 2 -d : | tr -d ' '| tr '\\n' \" \"");
double totalcpucap = 0;
for (String cpucap : cpucaps.split(" ")) {
totalcpucap += Double.parseDouble(cpucap);
if (StringUtils.isEmpty(cpucaps)) {
String totalCpus = Script.runSimpleBashScript("nproc --all| tr '\\n' \" \"");
String maxCpuSpeed = Script.runSimpleBashScript("lscpu | egrep 'CPU max MHz' | head -1 | cut -f 2 -d : | tr -d ' '| tr '\\n' \" \"");
if (StringUtils.isNotEmpty(totalCpus) && StringUtils.isNotEmpty(maxCpuSpeed)) {
totalcpucap = Double.parseDouble(totalCpus) * Double.parseDouble(maxCpuSpeed);
}
} else {
for (String cpucap : cpucaps.split(" ")) {
totalcpucap += Double.parseDouble(cpucap);
}
}
return totalcpucap;
}