diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/ExportersService.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/ExportersService.java index ce329e2ea3f0..82bccb1065b5 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/ExportersService.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/ExportersService.java @@ -20,6 +20,8 @@ package org.elasticsearch.marvel.monitor; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; @@ -67,6 +69,7 @@ public class ExportersService extends AbstractLifecycleComponent removed = newArrayList(); + List added = newArrayList(); + ImmutableSet currentBlocks = event.state().blocks().global(); + ImmutableSet previousBlocks = event.previousState().blocks().global(); + + for (ClusterBlock block : previousBlocks) { + if (!currentBlocks.contains(block)) { + removed.add(block); + } + } + for (ClusterBlock block : currentBlocks) { + if (!previousBlocks.contains(block)) { + added.add(block); + } + } + + for (ClusterBlock block : added) { + pendingEventsQueue.add(new ClusterEvent.ClusterBlock(timestamp, clusterName, block, true, event.source())); + } + + for (ClusterBlock block : removed) { + pendingEventsQueue.add(new ClusterEvent.ClusterBlock(timestamp, clusterName, block, false, event.source())); + } + } + + for (String index : event.indicesCreated()) { + pendingEventsQueue.add(new IndexEvent.IndexCreateDelete(timestamp, clusterName, index, true, event.source())); + } + + for (String index : event.indicesDeleted()) { + pendingEventsQueue.add(new IndexEvent.IndexCreateDelete(timestamp, clusterName, index, false, event.source())); + } + + // check for index & cluster status changes + ClusterHealthResponse prevHealth = new ClusterHealthResponse(clusterName, event.previousState().metaData().concreteAllIndices() + , event.previousState()); + ClusterHealthResponse curHealth = new ClusterHealthResponse(clusterName, event.state().metaData().concreteAllIndices(), event.state()); + + if (prevHealth.getStatus() != curHealth.getStatus()) { + pendingEventsQueue.add(new ClusterEvent.ClusterStatus(timestamp, clusterName, event.source(), curHealth)); + } + + for (ClusterIndexHealth indexHealth : curHealth) { + ClusterIndexHealth prevIndexHealth = prevHealth.getIndices().get(indexHealth.getIndex()); + if (prevIndexHealth != null && prevIndexHealth.getStatus() == indexHealth.getStatus()) { + continue; + } + + pendingEventsQueue.add(new IndexEvent.IndexStatus(timestamp, clusterName, event.source(), indexHealth)); } if (event.routingTableChanged()) { + // hunt for initializing shards RoutingNodes previousRoutingNodes = event.previousState().routingNodes(); for (ShardRouting shardRouting : event.state().routingNodes().shardsWithState(ShardRoutingState.INITIALIZING)) { @@ -320,11 +380,11 @@ public class ExportersService extends AbstractLifecycleComponent removed = newArrayList(); - List added = newArrayList(); - ImmutableSet currentBlocks = event.state().blocks().global(); - ImmutableSet previousBlocks = event.previousState().blocks().global(); - - for (ClusterBlock block : previousBlocks) { - if (!currentBlocks.contains(block)) { - removed.add(block); - } - } - for (ClusterBlock block : currentBlocks) { - if (!previousBlocks.contains(block)) { - added.add(block); - } - } - - for (ClusterBlock block : added) { - pendingEventsQueue.add(new ClusterEvent.ClusterBlock(timestamp, block, true, event.source())); - } - - for (ClusterBlock block : removed) { - pendingEventsQueue.add(new ClusterEvent.ClusterBlock(timestamp, block, false, event.source())); - } - } - - for (String index : event.indicesCreated()) { - pendingEventsQueue.add(new IndexEvent.IndexCreateDelete(timestamp, index, true, event.source())); - } - - for (String index : event.indicesDeleted()) { - pendingEventsQueue.add(new IndexEvent.IndexCreateDelete(timestamp, index, false, event.source())); - } - } + } @@ -383,7 +409,7 @@ public class ExportersService extends AbstractLifecycleComponent SHARD_LEVEL_MAP = ImmutableMap.of("level", "shards"); + + public IndexStatus(long timestamp, String clusterName, String event_source, ClusterIndexHealth indexHealth) { + super(timestamp, clusterName, event_source); + this.indexHealth = indexHealth; + } + + @Override + protected String event() { + return "index_status"; + } + + @Override + String conciseDescription() { + return "[" + indexHealth.getIndex() + "] status is " + indexHealth.getStatus().name(); + } + + @Override + public XContentBuilder addXContentBody(XContentBuilder builder, ToXContent.Params params) throws IOException { + super.addXContentBody(builder, params); + builder.field("index", indexHealth.getIndex()); + return indexHealth.toXContent(builder, new ToXContent.DelegatingMapParams(SHARD_LEVEL_MAP, params)); + } + } } diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/NodeEvent.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/NodeEvent.java index adfdd5d465ae..8c056d5b65ae 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/NodeEvent.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/NodeEvent.java @@ -30,8 +30,8 @@ public abstract class NodeEvent extends Event { protected final String event_source; - public NodeEvent(long timestamp, String event_source) { - super(timestamp); + public NodeEvent(long timestamp, String clusterName, String event_source) { + super(timestamp, clusterName); this.event_source = event_source; } @@ -55,8 +55,8 @@ public abstract class NodeEvent extends Event { private final DiscoveryNode node; - public ElectedAsMaster(long timestamp, DiscoveryNode node, String event_source) { - super(timestamp, event_source); + public ElectedAsMaster(long timestamp, String clusterName, DiscoveryNode node, String event_source) { + super(timestamp, clusterName, event_source); this.node = node; } @@ -67,7 +67,7 @@ public abstract class NodeEvent extends Event { @Override String conciseDescription() { - return node.toString() + " became master"; + return Utils.nodeDescription(node) + " became master"; } // no need to render node as XContent as it will be done by the exporter. @@ -78,8 +78,8 @@ public abstract class NodeEvent extends Event { private final DiscoveryNode node; private boolean joined; - public NodeJoinLeave(long timestamp, DiscoveryNode node, boolean joined, String event_source) { - super(timestamp, event_source); + public NodeJoinLeave(long timestamp, String clusterName, DiscoveryNode node, boolean joined, String event_source) { + super(timestamp, clusterName, event_source); this.node = node; this.joined = joined; } diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/RoutingEvent.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/RoutingEvent.java index 133d987fd34b..468959a309b0 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/RoutingEvent.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/RoutingEvent.java @@ -29,8 +29,8 @@ import java.io.IOException; public abstract class RoutingEvent extends Event { - public RoutingEvent(long timestamp) { - super(timestamp); + public RoutingEvent(long timestamp, String clusterName) { + super(timestamp, clusterName); } @Override @@ -56,8 +56,8 @@ public abstract class RoutingEvent extends Event { protected final ShardRouting shardRouting; protected final DiscoveryNode node; - public RoutingShardEvent(long timestamp, ShardRouting shardRouting, DiscoveryNode node) { - super(timestamp); + public RoutingShardEvent(long timestamp, String clusterName, ShardRouting shardRouting, DiscoveryNode node) { + super(timestamp, clusterName); this.node = node; this.shardRouting = shardRouting; } @@ -78,8 +78,8 @@ public abstract class RoutingEvent extends Event { public static class ShardInitializing extends RoutingShardEvent { - public ShardInitializing(long timestamp, ShardRouting shardRouting, DiscoveryNode node) { - super(timestamp, shardRouting, node); + public ShardInitializing(long timestamp, String clusterName, ShardRouting shardRouting, DiscoveryNode node) { + super(timestamp, clusterName, shardRouting, node); } @Override @@ -97,8 +97,9 @@ public abstract class RoutingEvent extends Event { final DiscoveryNode relocatingTo; - public ShardRelocating(long timestamp, ShardRouting shardRouting, DiscoveryNode node, DiscoveryNode relocatingTo) { - super(timestamp, shardRouting, node); + public ShardRelocating(long timestamp, String clusterName, ShardRouting shardRouting, + DiscoveryNode node, DiscoveryNode relocatingTo) { + super(timestamp, clusterName, shardRouting, node); this.relocatingTo = relocatingTo; } diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/ShardEvent.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/ShardEvent.java index c6f01fa8a4a9..c4977d80a7d8 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/ShardEvent.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/event/ShardEvent.java @@ -41,9 +41,9 @@ public class ShardEvent extends Event { private IndexShardState shardState; - public ShardEvent(long timestamp, IndexShardState shardState, ShardId shardId, DiscoveryNode node, + public ShardEvent(long timestamp, String clusterName, IndexShardState shardState, ShardId shardId, DiscoveryNode node, DiscoveryNode relocatingNode, ShardRouting shardRouting, String reason) { - super(timestamp); + super(timestamp, clusterName); this.shardState = shardState; this.shardId = shardId; this.reason = reason; diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/exporter/ESExporter.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/exporter/ESExporter.java index 3c823b0c69fb..4255e0b14ffa 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/exporter/ESExporter.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/exporter/ESExporter.java @@ -512,7 +512,7 @@ public class ESExporter extends AbstractLifecycleComponent implement @Override public void render(int index, XContentBuilder builder) throws IOException { builder.startObject(); - builder.field("cluster_name", clusterName.value()); + // events output cluster name. addNodeInfo(builder, "_source_node"); events[index].addXContentBody(builder, xContentParams); builder.endObject();