Skip to content

Add processor architectures to cluster stats #68264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/reference/cluster/stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public static class OsStats implements ToXContentFragment {
final int allocatedProcessors;
final ObjectIntHashMap<String> names;
final ObjectIntHashMap<String> prettyNames;
final ObjectIntHashMap<String> architectures;
final org.elasticsearch.monitor.os.OsStats.Mem mem;

/**
Expand All @@ -256,6 +257,7 @@ public static class OsStats implements ToXContentFragment {
private OsStats(List<NodeInfo> nodeInfos, List<NodeStats> nodeStatsList) {
this.names = new ObjectIntHashMap<>();
this.prettyNames = new ObjectIntHashMap<>();
this.architectures = new ObjectIntHashMap<>();
int availableProcessors = 0;
int allocatedProcessors = 0;
for (NodeInfo nodeInfo : nodeInfos) {
Expand All @@ -268,6 +270,9 @@ private OsStats(List<NodeInfo> nodeInfos, List<NodeStats> 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;
Expand Down Expand Up @@ -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";
}

Expand Down Expand Up @@ -340,6 +347,18 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params)
}
}
builder.endArray();
builder.startArray(Fields.ARCHITECTURES);
{
for (final ObjectIntCursor<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,"
Expand Down