Skip to content
This repository was archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Add node role flags and whether node is master to node rendering
Browse files Browse the repository at this point in the history
 This information appears in the _source_node section of all data except for node related information (node_stats+shard_stats) where this is under the `node` element.

 Closes elastic#108
  • Loading branch information
bleskes committed Feb 5, 2014
1 parent 7893cc1 commit b1b4c84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.shard.IndexShardState;
Expand Down Expand Up @@ -89,7 +88,7 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
@Inject
public AgentService(Settings settings, IndicesService indicesService,
NodeService nodeService, ClusterService clusterService,
Client client, Discovery discovery, ClusterName clusterName,
Client client, ClusterName clusterName,
Environment environment, Plugin marvelPlugin) {
super(settings);
this.indicesService = (InternalIndicesService) indicesService;
Expand All @@ -105,7 +104,7 @@ public AgentService(Settings settings, IndicesService indicesService,
pendingEventsQueue = ConcurrentCollections.newBlockingQueue();

if (componentSettings.getAsBoolean("enabled", true)) {
Exporter esExporter = new ESExporter(settings.getComponentSettings(ESExporter.class), discovery, clusterName, environment, marvelPlugin);
Exporter esExporter = new ESExporter(settings.getComponentSettings(ESExporter.class), clusterService, clusterName, environment, marvelPlugin);
this.exporters = ImmutableSet.of(esExporter);
} else {
this.exporters = ImmutableSet.of();
Expand Down
10 changes: 10 additions & 0 deletions agent/src/main/java/org/elasticsearch/marvel/agent/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
public class Utils {

public static XContentBuilder nodeToXContent(DiscoveryNode node, XContentBuilder builder) throws IOException {
return nodeToXContent(node, null, builder);
}

public static XContentBuilder nodeToXContent(DiscoveryNode node, Boolean isMasterNode, XContentBuilder builder) throws IOException {
builder.field("id", node.id());
builder.field("name", node.name());
builder.field("transport_address", node.address());
Expand All @@ -48,6 +52,12 @@ public static XContentBuilder nodeToXContent(DiscoveryNode node, XContentBuilder
builder.field("ip_port", "_" + node.address()); // will end up being "_local[ID]"
}

builder.field("master_node", node.isMasterNode());
builder.field("data_node", node.isDataNode());
if (isMasterNode != null) {
builder.field("master", isMasterNode.booleanValue());
}

if (!node.attributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attr : node.attributes().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.Base64;
import org.elasticsearch.common.collect.ImmutableMap;
Expand All @@ -40,7 +41,6 @@
import org.elasticsearch.common.xcontent.*;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.smile.SmileXContent;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.env.Environment;
import org.elasticsearch.marvel.agent.Plugin;
import org.elasticsearch.marvel.agent.Utils;
Expand All @@ -64,7 +64,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
final String kibanaIndex;
final String[] dashboardPathsToUpload;

final Discovery discovery;
final ClusterService clusterService;
final ClusterName clusterName;

public final static DateTimeFormatter defaultDatePrinter = Joda.forPattern("date_time").printer();
Expand All @@ -81,10 +81,11 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
ConnectionKeepAliveWorker keepAliveWorker;
Thread keepAliveThread;

public ESExporter(Settings settings, Discovery discovery, ClusterName clusterName, Environment environment, Plugin marvelPlugin) {
public ESExporter(Settings settings, ClusterService clusterService, ClusterName clusterName, Environment environment, Plugin marvelPlugin) {
super(settings);

this.discovery = discovery;
this.clusterService = clusterService;

this.clusterName = clusterName;

hosts = settings.getAsArray("es.hosts", new String[]{"localhost:9200"});
Expand Down Expand Up @@ -503,7 +504,7 @@ private void addNodeInfo(XContentBuilder builder) throws IOException {

private void addNodeInfo(XContentBuilder builder, String fieldname) throws IOException {
builder.startObject(fieldname);
Utils.nodeToXContent(discovery.localNode(), builder);
Utils.nodeToXContent(clusterService.localNode(), clusterService.state().nodes().localNodeMaster(), builder);
builder.endObject();
}

Expand Down

0 comments on commit b1b4c84

Please sign in to comment.