From 47cc5713b9ee2c71b456b8ac924c37b30e077db5 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Thu, 21 Nov 2013 12:07:24 +0100 Subject: [PATCH] Allow to configure which indices's stats are exported. Tweaked logging and naming. --- .../marvel/monitor/StatsExportersService.java | 31 ++++++++++++++++--- .../marvel/monitor/exporter/ESExporter.java | 14 ++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/exporter/src/main/java/org/elasticsearch/marvel/monitor/StatsExportersService.java b/exporter/src/main/java/org/elasticsearch/marvel/monitor/StatsExportersService.java index 54282cf1f95f..e27db4cef2a0 100644 --- a/exporter/src/main/java/org/elasticsearch/marvel/monitor/StatsExportersService.java +++ b/exporter/src/main/java/org/elasticsearch/marvel/monitor/StatsExportersService.java @@ -24,10 +24,13 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.admin.indices.stats.ShardStats; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableSet; +import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -35,21 +38,22 @@ 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.index.service.IndexService; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesLifecycle; +import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.indices.InternalIndicesService; import org.elasticsearch.marvel.monitor.annotation.Annotation; import org.elasticsearch.marvel.monitor.annotation.ShardEventAnnotation; import org.elasticsearch.marvel.monitor.exporter.ESExporter; import org.elasticsearch.marvel.monitor.exporter.StatsExporter; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.indices.InternalIndicesService; import org.elasticsearch.node.service.NodeService; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingDeque; public class StatsExportersService extends AbstractLifecycleComponent { @@ -66,6 +70,8 @@ public class StatsExportersService extends AbstractLifecycleComponent exporters; + private String[] indicesToExport = Strings.EMPTY_ARRAY; + private final BlockingQueue pendingAnnotationsQueue; @Inject @@ -78,6 +84,7 @@ public class StatsExportersService extends AbstractLifecycleComponent shardStats = Lists.newArrayList(); + for (String index : indices) { + IndexService indexService = indicesService.indexService(index); + if (indexService == null) { + continue; // something changed, move along + } + for (int shardId : indexService.shardIds()) { + IndexShard indexShard = indexService.shard(shardId); + if (indexShard == null) { + continue; + } + shardStats.add(new ShardStats(indexShard, CommonStatsFlags.ALL)); + } + } + ShardStats[] shardStatsArray = shardStats.toArray(new ShardStats[shardStats.size()]); logger.debug("Exporting shards stats"); for (StatsExporter e : exporters) { 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 c65013d78ad2..7361be97604b 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 @@ -85,12 +85,12 @@ public class ESExporter extends AbstractLifecycleComponent implement this.hostname = address == null ? null : address.getHostName(); - hosts = settings.getAsArray("hosts", new String[]{"localhost:9200"}); - indexPrefix = settings.get("index.prefix", ".marvel"); - String indexTimeFormat = settings.get("index.timeformat", "YYYY.MM.dd"); + hosts = settings.getAsArray("es.hosts", new String[]{"localhost:9200"}); + indexPrefix = settings.get("es.index.prefix", ".marvel"); + String indexTimeFormat = settings.get("es.index.timeformat", "YYYY.MM.dd"); indexTimeFormatter = DateTimeFormat.forPattern(indexTimeFormat).withZoneUTC(); - timeout = (int) settings.getAsTime("timeout", new TimeValue(6000)).seconds(); + timeout = (int) settings.getAsTime("es.timeout", new TimeValue(6000)).seconds(); nodeStatsRenderer = new NodeStatsRenderer(); shardStatsRenderer = new ShardStatsRenderer(); @@ -98,12 +98,12 @@ public class ESExporter extends AbstractLifecycleComponent implement indicesStatsRenderer = new IndicesStatsRenderer(); annotationsRenderer = new AnnotationsRenderer(); - logger.info("ESExporter initialized. Targets: {}, index prefix [{}], index time format [{}]", hosts, indexPrefix, indexTimeFormat); + logger.info("Initialized with targets: {}, index prefix [{}], index time format [{}]", hosts, indexPrefix, indexTimeFormat); } @Override public String name() { - return "ESExporter"; + return "es_exporter"; } @@ -265,7 +265,7 @@ public class ESExporter extends AbstractLifecycleComponent implement try { - String templateName = "marvel.monitor." + indexPrefix; + String templateName = "marvel.monitor.prefix-" + indexPrefix; logger.debug("checking of target has template [{}]", templateName); // DO HEAD REQUEST, when elasticsearch supports it