diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java index 1a05b03436495..23fe4d465435e 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java @@ -112,7 +112,8 @@ protected Collection doCollect(final MonitoringDoc.Node node, // Adds a cluster stats document return Collections.singleton( new ClusterStatsMonitoringDoc(clusterUuid, timestamp(), interval, node, clusterName, version, clusterStats.getStatus(), - license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterNeedsTLSEnabled)); + license, apmIndicesExist, xpackUsage, clusterStats, clusterState, + clusterNeedsTLSEnabled)); } boolean doAPMIndicesExist(final ClusterState clusterState) { diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index 414945c2a151b..75c0ba6b81c7d 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -8,10 +8,12 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.License; @@ -45,6 +47,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { ClusterState.Metric.NODES)); public static final String TYPE = "cluster_stats"; + protected static final String SETTING_CLUSTER_METADATA = "cluster.metadata"; private final String clusterName; private final String version; @@ -118,6 +121,14 @@ boolean getClusterNeedsTLSEnabled() { return clusterNeedsTLSEnabled; } + Settings getClusterMetaDataSettings() { + MetaData metaData = this.clusterState.getMetaData(); + if (metaData == null) { + return Settings.EMPTY; + } + return metaData.settings().getAsSettings(SETTING_CLUSTER_METADATA); + } + @Override protected void innerToXContent(XContentBuilder builder, Params params) throws IOException { builder.field("cluster_name", clusterName); @@ -156,6 +167,25 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO builder.endObject(); } + Settings clusterMetaDataSettings = getClusterMetaDataSettings(); + if (clusterMetaDataSettings != null) { + builder.startObject("cluster_settings"); + { + if (clusterMetaDataSettings.size() > 0) { + builder.startObject("cluster"); + { + builder.startObject("metadata"); + { + clusterMetaDataSettings.toXContent(builder, params); + } + builder.endObject(); + } + builder.endObject(); + } + } + builder.endObject(); + } + builder.startObject("stack_stats"); { // in the future, it may be useful to pass in an object that represents APM (and others), but for now this 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 61224ac0fd735..bc531bb2d6b44 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 @@ -203,7 +203,12 @@ public void testToXContent() throws IOException { Version.V_6_0_0_beta1); final ClusterState clusterState = ClusterState.builder(clusterName) - .metaData(MetaData.builder().clusterUUID(clusterUuid).build()) + .metaData(MetaData.builder() + .clusterUUID(clusterUuid) + .transientSettings(Settings.builder() + .put("cluster.metadata.display_name", "my_prod_cluster") + .build()) + .build()) .stateUUID("_state_uuid") .version(12L) .nodes(DiscoveryNodes.builder() @@ -521,6 +526,13 @@ public void testToXContent() throws IOException { + "}" + "}" + "}," + + "\"cluster_settings\":{" + + "\"cluster\":{" + + "\"metadata\":{" + + "\"display_name\":\"my_prod_cluster\"" + + "}" + + "}" + + "}," + "\"stack_stats\":{" + "\"apm\":{" + "\"found\":" + apmIndicesExist