From fd669bca51fe94ae3f958fbcb843a4666a50b57b Mon Sep 17 00:00:00 2001 From: David Roberts Date: Mon, 1 Feb 2021 09:15:44 +0000 Subject: [PATCH 1/2] 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. --- 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 49fa908ae3e8b..3a7e31899bc89 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); + { + architectures (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," From 0d1bfe85fc4d8aff3c2bb905554ee2ec577e5824 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Mon, 1 Feb 2021 09:34:35 +0000 Subject: [PATCH 2/2] Fix wrong window pasting error --- .../action/admin/cluster/stats/ClusterStatsNodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a7e31899bc89..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 @@ -349,7 +349,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) builder.endArray(); builder.startArray(Fields.ARCHITECTURES); { - architectures (final ObjectIntCursor arch : architectures) { + for (final ObjectIntCursor arch : architectures) { builder.startObject(); { builder.field(Fields.ARCH, arch.key);