diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java index 017b4481240..71ec050b481 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -21,11 +21,12 @@ package org.elasticsearch.action.admin.cluster.stats; import com.carrotsearch.hppc.ObjectIntHashMap; import com.carrotsearch.hppc.cursors.ObjectIntCursor; - import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; @@ -39,11 +40,13 @@ import org.elasticsearch.plugins.PluginInfo; import java.io.IOException; import java.net.InetAddress; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; public class ClusterStatsNodes implements ToXContent { @@ -54,6 +57,7 @@ public class ClusterStatsNodes implements ToXContent { private final JvmStats jvm; private final FsInfo.Path fs; private final Set plugins; + private final NetworkTypes networkTypes; ClusterStatsNodes(List nodeResponses) { this.versions = new HashSet<>(); @@ -86,6 +90,7 @@ public class ClusterStatsNodes implements ToXContent { this.os = new OsStats(nodeInfos); this.process = new ProcessStats(nodeStats); this.jvm = new JvmStats(nodeInfos, nodeStats); + this.networkTypes = new NetworkTypes(nodeInfos); } public Counts getCounts() { @@ -124,6 +129,7 @@ public class ClusterStatsNodes implements ToXContent { static final String JVM = "jvm"; static final String FS = "fs"; static final String PLUGINS = "plugins"; + static final String NETWORK_TYPES = "network_types"; } @Override @@ -158,6 +164,10 @@ public class ClusterStatsNodes implements ToXContent { pluginInfo.toXContent(builder, params); } builder.endArray(); + + builder.startObject(Fields.NETWORK_TYPES); + networkTypes.toXContent(builder, params); + builder.endObject(); return builder; } @@ -506,4 +516,43 @@ public class ClusterStatsNodes implements ToXContent { return vmVersion.hashCode(); } } + + static class NetworkTypes implements ToXContent { + + private final Map transportTypes; + private final Map httpTypes; + + private NetworkTypes(final List nodeInfos) { + final Map transportTypes = new HashMap<>(); + final Map httpTypes = new HashMap<>(); + for (final NodeInfo nodeInfo : nodeInfos) { + final Settings settings = nodeInfo.getSettings(); + final String transportType = + settings.get(NetworkModule.TRANSPORT_TYPE_KEY, NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.get(settings)); + final String httpType = + settings.get(NetworkModule.HTTP_TYPE_KEY, NetworkModule.HTTP_DEFAULT_TYPE_SETTING.get(settings)); + transportTypes.computeIfAbsent(transportType, k -> new AtomicInteger()).incrementAndGet(); + httpTypes.computeIfAbsent(httpType, k -> new AtomicInteger()).incrementAndGet(); + } + this.transportTypes = Collections.unmodifiableMap(transportTypes); + this.httpTypes = Collections.unmodifiableMap(httpTypes); + } + + @Override + public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { + builder.startObject("transport_types"); + for (final Map.Entry entry : transportTypes.entrySet()) { + builder.field(entry.getKey(), entry.getValue().get()); + } + builder.endObject(); + builder.startObject("http_types"); + for (final Map.Entry entry : httpTypes.entrySet()) { + builder.field(entry.getKey(), entry.getValue().get()); + } + builder.endObject(); + return builder; + } + + } + } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java index bc894952370..72287c84662 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java @@ -91,7 +91,7 @@ public class TransportClusterStatsAction extends TransportNodesAction shardsStats = new ArrayList<>(); for (IndexService indexService : indicesService) { diff --git a/modules/transport-netty3/src/test/resources/rest-api-spec/test/10_basic.yaml b/modules/transport-netty3/src/test/resources/rest-api-spec/test/10_basic.yaml index e25074fb90c..b2267343ecd 100644 --- a/modules/transport-netty3/src/test/resources/rest-api-spec/test/10_basic.yaml +++ b/modules/transport-netty3/src/test/resources/rest-api-spec/test/10_basic.yaml @@ -11,3 +11,9 @@ nodes.info: {} - match: { nodes.$master.modules.0.name: transport-netty3 } + + - do: + cluster.stats: {} + + - match: { nodes.network_types.transport_types.netty3: 2 } + - match: { nodes.network_types.http_types.netty3: 2 } diff --git a/modules/transport-netty4/src/test/resources/rest-api-spec/test/10_basic.yaml b/modules/transport-netty4/src/test/resources/rest-api-spec/test/10_basic.yaml index a7beac1491f..ddf956e2c11 100644 --- a/modules/transport-netty4/src/test/resources/rest-api-spec/test/10_basic.yaml +++ b/modules/transport-netty4/src/test/resources/rest-api-spec/test/10_basic.yaml @@ -11,3 +11,9 @@ nodes.info: {} - match: { nodes.$master.modules.1.name: transport-netty4 } + + - do: + cluster.stats: {} + + - match: { nodes.network_types.transport_types.netty4: 2 } + - match: { nodes.network_types.http_types.netty4: 2 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yaml index 236ad876d09..08d13e04bea 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yaml @@ -23,3 +23,4 @@ - is_true: nodes.jvm - is_true: nodes.fs - is_true: nodes.plugins + - is_true: nodes.network_types