diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java index a3e64c7dff0..5512c48cf97 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -397,8 +397,8 @@ public class ClusterStatsNodes implements ToXContent, Streamable { int count; int cpuPercent; long totalOpenFileDescriptors; - long minOpenFileDescriptors = Integer.MAX_VALUE; - long maxOpenFileDescriptors = Integer.MIN_VALUE; + long minOpenFileDescriptors = Long.MAX_VALUE; + long maxOpenFileDescriptors = Long.MIN_VALUE; public void addNodeStats(NodeStats nodeStats) { if (nodeStats.getProcess() == null) { @@ -410,7 +410,11 @@ public class ClusterStatsNodes implements ToXContent, Streamable { cpuPercent += nodeStats.getProcess().cpu().getPercent(); } long fd = nodeStats.getProcess().openFileDescriptors(); - totalOpenFileDescriptors += fd; + if (fd > 0) { + // fd can be -1 if not supported on platform + totalOpenFileDescriptors += fd; + } + // we still do min max calc on -1, so we'll have an indication of it not being supported on one of the nodes. minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd); maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd); } diff --git a/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java b/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java index 969fd0c8d37..106c2d9fcd4 100644 --- a/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java +++ b/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java @@ -136,9 +136,12 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest { assertThat(response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true)); assertThat(response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0)); - assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThan(0L)); - assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(0L)); - assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(0L)); + assertThat(response.nodesStats.getProcess().count, Matchers.greaterThan(0)); + // 0 happens when not supported on platform + assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(0L)); + // these can be -1 if not supported + assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(-1L)); + assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(-1L)); } }