This is an automated email from the ASF dual-hosted git repository.
pearl11594 pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new 54c1f92efd2 Fix Stats Collector to not divide by zero (#10492)
54c1f92efd2 is described below
commit 54c1f92efd2664d5316c67c451e69e97f880a5f3
Author: Lucas Martins <[email protected]>
AuthorDate: Mon Mar 10 12:39:08 2025 -0300
Fix Stats Collector to not divide by zero (#10492)
* Set loadHistory value to zero when interval is zero to not throw
arithmatic exception
* Change loadHistory value to -1 and fix maxsize bug
---------
Co-authored-by: Lucas Martins <[email protected]>
---
server/src/main/java/com/cloud/server/StatsCollector.java | 4 ++--
1 file changed, 2 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 5934716da66..27ac0bb725d 100644
--- a/server/src/main/java/com/cloud/server/StatsCollector.java
+++ b/server/src/main/java/com/cloud/server/StatsCollector.java
@@ -718,10 +718,10 @@ public class StatsCollector extends ManagerBase
implements ComponentMethodInterc
getDynamicDataFromDB();
long interval = (Long) dbStats.get(uptime) - lastUptime;
long activity = (Long) dbStats.get(queries) - lastQueries;
- loadHistory.add(0, Double.valueOf(activity / interval));
+ loadHistory.add(0, interval == 0 ? -1 :
Double.valueOf(activity / interval));
int maxsize =
DATABASE_SERVER_LOAD_HISTORY_RETENTION_NUMBER.value();
while (loadHistory.size() > maxsize) {
- loadHistory.remove(maxsize - 1);
+ loadHistory.remove(maxsize);
}
} catch (Throwable e) {
// pokemon catch to make sure the thread stays running