Skip to content

Commit e990c0a

Browse files
authored
Fix incorrect stats warning when swap is disabled (#57983)
1 parent bb66d59 commit e990c0a

File tree

1 file changed

+6
-2
lines changed
  • server/src/main/java/org/elasticsearch/monitor/os

1 file changed

+6
-2
lines changed

server/src/main/java/org/elasticsearch/monitor/os/OsStats.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ public ByteSizeValue getUsed() {
220220
//
221221
// We intentionally check for (total == 0) rather than (total - free < 0) so as not to hide
222222
// cases where (free > total) which would be a different bug.
223-
logger.warn("cannot compute used swap when total swap is 0 and free swap is " + free);
223+
if (free > 0) {
224+
logger.warn("cannot compute used swap when total swap is 0 and free swap is " + free);
225+
}
224226
return new ByteSizeValue(0);
225227
}
226228
return new ByteSizeValue(total - free);
@@ -280,7 +282,9 @@ public ByteSizeValue getUsed() {
280282
//
281283
// We intentionally check for (total == 0) rather than (total - free < 0) so as not to hide
282284
// cases where (free > total) which would be a different bug.
283-
logger.warn("cannot compute used memory when total memory is 0 and free memory is " + free);
285+
if (free > 0) {
286+
logger.warn("cannot compute used memory when total memory is 0 and free memory is " + free);
287+
}
284288
return new ByteSizeValue(0);
285289
}
286290
return new ByteSizeValue(total - free);

0 commit comments

Comments
 (0)