diff --git a/docs/reference/cluster/stats.asciidoc b/docs/reference/cluster/stats.asciidoc index 1c90c49d3c67e..64fa4ceb1fce2 100644 --- a/docs/reference/cluster/stats.asciidoc +++ b/docs/reference/cluster/stats.asciidoc @@ -766,6 +766,23 @@ Human-readable name of an operating system used by one or more selected nodes. Number of selected nodes using the operating system. ====== +`architectures`:: +(array of objects) +Contains statistics about processor architectures (for example, x86_64 or +aarch64) used by selected nodes. ++ +.Properties of `architectures` +[%collapsible%open] +====== +`arch`::: +(string) +Name of an architecture used by one or more selected nodes. + +`count`::: +(string) +Number of selected nodes using the architecture. +====== + `mem`:: (object) Contains statistics about memory used by selected nodes. @@ -1252,6 +1269,12 @@ The API returns the following response: "count": 1 } ], + "architectures": [ + { + "arch": "x86_64", + "count": 1 + } + ], "mem" : { "total" : "16gb", "total_in_bytes" : 17179869184, diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java index 49fa908ae3e8b..ba0bba6df0fdf 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -248,6 +248,7 @@ public static class OsStats implements ToXContentFragment { final int allocatedProcessors; final ObjectIntHashMap names; final ObjectIntHashMap prettyNames; + final ObjectIntHashMap architectures; final org.elasticsearch.monitor.os.OsStats.Mem mem; /** @@ -256,6 +257,7 @@ public static class OsStats implements ToXContentFragment { private OsStats(List nodeInfos, List nodeStatsList) { this.names = new ObjectIntHashMap<>(); this.prettyNames = new ObjectIntHashMap<>(); + this.architectures = new ObjectIntHashMap<>(); int availableProcessors = 0; int allocatedProcessors = 0; for (NodeInfo nodeInfo : nodeInfos) { @@ -268,6 +270,9 @@ private OsStats(List nodeInfos, List nodeStatsList) { if (nodeInfo.getInfo(OsInfo.class).getPrettyName() != null) { prettyNames.addTo(nodeInfo.getInfo(OsInfo.class).getPrettyName(), 1); } + if (nodeInfo.getInfo(OsInfo.class).getArch() != null) { + architectures.addTo(nodeInfo.getInfo(OsInfo.class).getArch(), 1); + } } this.availableProcessors = availableProcessors; this.allocatedProcessors = allocatedProcessors; @@ -308,6 +313,8 @@ static final class Fields { static final String NAMES = "names"; static final String PRETTY_NAME = "pretty_name"; static final String PRETTY_NAMES = "pretty_names"; + static final String ARCH = "arch"; + static final String ARCHITECTURES = "architectures"; static final String COUNT = "count"; } @@ -340,6 +347,18 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) } } builder.endArray(); + builder.startArray(Fields.ARCHITECTURES); + { + for (final ObjectIntCursor arch : architectures) { + builder.startObject(); + { + builder.field(Fields.ARCH, arch.key); + builder.field(Fields.COUNT, arch.value); + } + builder.endObject(); + } + } + builder.endArray(); mem.toXContent(builder, params); return builder; } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index e8282ad6dc529..e6fad27cf71b5 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -269,6 +269,7 @@ public void testToXContent() throws IOException { when(mockOsInfo.getAllocatedProcessors()).thenReturn(16); when(mockOsInfo.getName()).thenReturn("_os_name"); when(mockOsInfo.getPrettyName()).thenReturn("_pretty_os_name"); + when(mockOsInfo.getArch()).thenReturn("_architecture"); final JvmInfo mockJvmInfo = mock(JvmInfo.class); when(mockNodeInfo.getInfo(JvmInfo.class)).thenReturn(mockJvmInfo); @@ -495,6 +496,12 @@ public void testToXContent() throws IOException { + " \"count\": 1" + " }" + " ]," + + " \"architectures\": [" + + " {" + + " \"arch\": \"_architecture\"," + + " \"count\": 1" + + " }" + + " ]," + " \"mem\": {" + " \"total_in_bytes\": 100," + " \"free_in_bytes\": 79,"