This is an automated email from the ASF dual-hosted git repository.
weizhou pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push:
new bde80f14aac Fix NPE in management server logs due to /proc/cpuinfo
output (#7765)
bde80f14aac is described below
commit bde80f14aac1a9bf741c7de3f54ee053175c94e5
Author: Rohit Yadav <[email protected]>
AuthorDate: Tue Jul 25 08:13:33 2023 +0530
Fix NPE in management server logs due to /proc/cpuinfo output (#7765)
Signed-off-by: Rohit Yadav <[email protected]>
---
server/src/main/java/com/cloud/server/StatsCollector.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/com/cloud/server/StatsCollector.java
b/server/src/main/java/com/cloud/server/StatsCollector.java
index 5197ccc3a3c..91410198e2f 100644
--- a/server/src/main/java/com/cloud/server/StatsCollector.java
+++ b/server/src/main/java/com/cloud/server/StatsCollector.java
@@ -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;
}