Skip to content

Commit 54c1f92

Browse files
lucas-a-martinsLucas Martins
andauthored
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]>
1 parent 0427abf commit 54c1f92

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,10 @@ protected void runInContext() {
718718
getDynamicDataFromDB();
719719
long interval = (Long) dbStats.get(uptime) - lastUptime;
720720
long activity = (Long) dbStats.get(queries) - lastQueries;
721-
loadHistory.add(0, Double.valueOf(activity / interval));
721+
loadHistory.add(0, interval == 0 ? -1 : Double.valueOf(activity / interval));
722722
int maxsize = DATABASE_SERVER_LOAD_HISTORY_RETENTION_NUMBER.value();
723723
while (loadHistory.size() > maxsize) {
724-
loadHistory.remove(maxsize - 1);
724+
loadHistory.remove(maxsize);
725725
}
726726
} catch (Throwable e) {
727727
// pokemon catch to make sure the thread stays running

0 commit comments

Comments
 (0)