From bffce738766945c8dd9895adc50ae740ef0d7d3c Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 2 Feb 2021 09:48:20 +0000 Subject: [PATCH] Add processor architectures to cluster stats This change adds a new "architectures" section to the cluster stats, containing a summary of how many nodes in the cluster are on each processor architecture. The intention is to make it easier to see whether clusters are running on aarch64, or mixed x86_64/aarch64, which may aid support as aarch64 becomes more commonly used. Backport of #68264 --- docs/reference/cluster/stats.asciidoc | 23 +++++++++++++++++++ .../cluster/stats/ClusterStatsNodes.java | 19 +++++++++++++++ .../ClusterStatsMonitoringDocTests.java | 7 ++++++ 3 files changed, 49 insertions(+) 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 02f85e327ab48..300332e49c705 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 a4828ac701f6a..ed631518bbabb 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 @@ -267,6 +267,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); @@ -492,6 +493,12 @@ public void testToXContent() throws IOException { + "\"count\":1" + "}" + "]," + + "\"architectures\":[" + + "{" + + "\"arch\":\"_architecture\"," + + "\"count\":1" + + "}" + + "]," + "\"mem\":{" + "\"total_in_bytes\":100," + "\"free_in_bytes\":79,"