Marvel: rename index stats collector

Original commit: elastic/x-pack-elasticsearch@489e43517c
This commit is contained in:
Tanguy Leroux 2015-07-21 11:43:41 +02:00
parent a1870b70bf
commit 8178b799fd
7 changed files with 129 additions and 129 deletions

View File

@ -7,7 +7,7 @@ package org.elasticsearch.marvel.agent.collector;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.marvel.agent.collector.indices.IndexCollector; import org.elasticsearch.marvel.agent.collector.indices.IndexStatsCollector;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -18,7 +18,7 @@ public class CollectorModule extends AbstractModule {
public CollectorModule() { public CollectorModule() {
// Registers default collectors // Registers default collectors
registerCollector(IndexCollector.class); registerCollector(IndexStatsCollector.class);
} }
@Override @Override

View File

@ -21,19 +21,19 @@ import java.util.Collection;
/** /**
* Collector for indices statistics. * Collector for indices statistics.
* *
* This collector runs on the master node only and collect a {@link IndexMarvelDoc} document * This collector runs on the master node only and collect a {@link IndexStatsMarvelDoc} document
* for each existing index in the cluster. * for each existing index in the cluster.
*/ */
public class IndexCollector extends AbstractCollector<IndexCollector> { public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector> {
public static final String NAME = "index-collector"; public static final String NAME = "index-stats-collector";
protected static final String TYPE = "marvel_index"; protected static final String TYPE = "marvel_index";
private final ClusterName clusterName; private final ClusterName clusterName;
private final Client client; private final Client client;
@Inject @Inject
public IndexCollector(Settings settings, ClusterService clusterService, ClusterName clusterName, Client client) { public IndexStatsCollector(Settings settings, ClusterService clusterService, ClusterName clusterName, Client client) {
super(settings, NAME, clusterService); super(settings, NAME, clusterService);
this.client = client; this.client = client;
this.clusterName = clusterName; this.clusterName = clusterName;
@ -62,7 +62,7 @@ public class IndexCollector extends AbstractCollector<IndexCollector> {
} }
protected MarvelDoc buildMarvelDoc(String clusterName, String type, long timestamp, IndexStats indexStats) { protected MarvelDoc buildMarvelDoc(String clusterName, String type, long timestamp, IndexStats indexStats) {
return IndexMarvelDoc.createMarvelDoc(clusterName, type, timestamp, return IndexStatsMarvelDoc.createMarvelDoc(clusterName, type, timestamp,
indexStats.getIndex(), indexStats.getIndex(),
indexStats.getTotal().getDocs().getCount(), indexStats.getTotal().getDocs().getCount(),
indexStats.getTotal().getStore().sizeInBytes(), indexStats.getTotal().getStore().throttleTime().millis(), indexStats.getTotal().getStore().sizeInBytes(), indexStats.getTotal().getStore().throttleTime().millis(),

View File

@ -14,14 +14,14 @@ import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class IndexMarvelDoc extends MarvelDoc<IndexMarvelDoc> { public class IndexStatsMarvelDoc extends MarvelDoc<IndexStatsMarvelDoc> {
private final String index; private final String index;
private final Docs docs; private final Docs docs;
private final Store store; private final Store store;
private final Indexing indexing; private final Indexing indexing;
public IndexMarvelDoc(String clusterName, String type, long timestamp, public IndexStatsMarvelDoc(String clusterName, String type, long timestamp,
String index, Docs docs, Store store, Indexing indexing) { String index, Docs docs, Store store, Indexing indexing) {
super(clusterName, type, timestamp); super(clusterName, type, timestamp);
this.index = index; this.index = index;
@ -31,7 +31,7 @@ public class IndexMarvelDoc extends MarvelDoc<IndexMarvelDoc> {
} }
@Override @Override
public IndexMarvelDoc payload() { public IndexStatsMarvelDoc payload() {
return this; return this;
} }
@ -69,9 +69,9 @@ public class IndexMarvelDoc extends MarvelDoc<IndexMarvelDoc> {
return builder; return builder;
} }
public static IndexMarvelDoc createMarvelDoc(String clusterName, String type, long timestamp, public static IndexStatsMarvelDoc createMarvelDoc(String clusterName, String type, long timestamp,
String index, long docsCount, long storeSizeInBytes, long storeThrottleTimeInMillis, long indexingThrottleTimeInMillis) { String index, long docsCount, long storeSizeInBytes, long storeThrottleTimeInMillis, long indexingThrottleTimeInMillis) {
return new IndexMarvelDoc(clusterName, type, timestamp, index, return new IndexStatsMarvelDoc(clusterName, type, timestamp, index,
new Docs(docsCount), new Docs(docsCount),
new Store(storeSizeInBytes, storeThrottleTimeInMillis), new Store(storeSizeInBytes, storeThrottleTimeInMillis),
new Indexing(indexingThrottleTimeInMillis)); new Indexing(indexingThrottleTimeInMillis));

View File

@ -1,112 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.agent.collector.indices;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Collection;
import java.util.Iterator;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.*;
public class IndexCollectorTests extends ElasticsearchSingleNodeTest {
@Test
public void testIndexCollectorNoIndices() throws Exception {
Collection<MarvelDoc> results = newIndexCollector().doCollect();
assertThat(results, is(empty()));
}
@Test
public void testIndexCollectorOneIndex() throws Exception {
int nbDocs = randomIntBetween(1, 20);
for (int i = 0; i < nbDocs; i++) {
client().prepareIndex("test", "test").setSource("num", i).get();
}
client().admin().indices().prepareRefresh().get();
assertHitCount(client().prepareCount().get(), nbDocs);
Collection<MarvelDoc> results = newIndexCollector().doCollect();
assertThat(results, hasSize(1));
MarvelDoc marvelDoc = results.iterator().next();
assertNotNull(marvelDoc);
assertThat(marvelDoc, instanceOf(IndexMarvelDoc.class));
IndexMarvelDoc indexMarvelDoc = (IndexMarvelDoc) marvelDoc;
assertThat(indexMarvelDoc.clusterName(), equalTo(client().admin().cluster().prepareHealth().get().getClusterName()));
assertThat(indexMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexMarvelDoc.type(), equalTo(IndexCollector.TYPE));
assertThat(indexMarvelDoc.getIndex(), equalTo("test"));
assertNotNull(indexMarvelDoc.getDocs());
assertThat(indexMarvelDoc.getDocs().getCount(), equalTo((long) nbDocs));
assertNotNull(indexMarvelDoc.getStore());
assertThat(indexMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L));
assertNotNull(indexMarvelDoc.getIndexing());
assertThat(indexMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L));
}
@Test
public void testIndexCollectorMultipleIndices() throws Exception {
int nbIndices = randomIntBetween(1, 5);
int[] docsPerIndex = new int[nbIndices];
for (int i = 0; i < nbIndices; i++) {
docsPerIndex[i] = randomIntBetween(1, 20);
for (int j = 0; j < docsPerIndex[i]; j++) {
client().prepareIndex("test-" + i, "test").setSource("num", i).get();
}
}
String clusterName = client().admin().cluster().prepareHealth().get().getClusterName();
client().admin().indices().prepareRefresh().get();
for (int i = 0; i < nbIndices; i++) {
assertHitCount(client().prepareCount("test-" + i).get(), docsPerIndex[i]);
}
Collection<MarvelDoc> results = newIndexCollector().doCollect();
assertThat(results, hasSize(nbIndices));
for (int i = 0; i < nbIndices; i++) {
boolean found = false;
Iterator<MarvelDoc> it = results.iterator();
while (!found && it.hasNext()) {
MarvelDoc marvelDoc = it.next();
assertThat(marvelDoc, instanceOf(IndexMarvelDoc.class));
IndexMarvelDoc indexMarvelDoc = (IndexMarvelDoc) marvelDoc;
if (indexMarvelDoc.getIndex().equals("test-" + i)) {
assertThat(indexMarvelDoc.clusterName(), equalTo(clusterName));
assertThat(indexMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexMarvelDoc.type(), equalTo(IndexCollector.TYPE));
assertNotNull(indexMarvelDoc.getDocs());
assertThat(indexMarvelDoc.getDocs().getCount(), equalTo((long) docsPerIndex[i]));
assertNotNull(indexMarvelDoc.getStore());
assertThat(indexMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L));
assertNotNull(indexMarvelDoc.getIndexing());
assertThat(indexMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L));
found = true;
}
}
assertThat("could not find collected stats for index [test-" + i + "]", found, is(true));
}
}
private IndexCollector newIndexCollector() {
return new IndexCollector(getInstanceFromNode(Settings.class), getInstanceFromNode(ClusterService.class), getInstanceFromNode(ClusterName.class), client());
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.agent.collector.indices;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Collection;
import java.util.Iterator;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.*;
public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest {
@Test
public void testIndexStatsCollectorNoIndices() throws Exception {
Collection<MarvelDoc> results = newIndexStatsCollector().doCollect();
assertThat(results, is(empty()));
}
@Test
public void testIndexStatsCollectorOneIndex() throws Exception {
int nbDocs = randomIntBetween(1, 20);
for (int i = 0; i < nbDocs; i++) {
client().prepareIndex("test", "test").setSource("num", i).get();
}
client().admin().indices().prepareRefresh().get();
assertHitCount(client().prepareCount().get(), nbDocs);
Collection<MarvelDoc> results = newIndexStatsCollector().doCollect();
assertThat(results, hasSize(1));
MarvelDoc marvelDoc = results.iterator().next();
assertNotNull(marvelDoc);
assertThat(marvelDoc, instanceOf(IndexStatsMarvelDoc.class));
IndexStatsMarvelDoc indexStatsMarvelDoc = (IndexStatsMarvelDoc) marvelDoc;
assertThat(indexStatsMarvelDoc.clusterName(), equalTo(client().admin().cluster().prepareHealth().get().getClusterName()));
assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE));
assertThat(indexStatsMarvelDoc.getIndex(), equalTo("test"));
assertNotNull(indexStatsMarvelDoc.getDocs());
assertThat(indexStatsMarvelDoc.getDocs().getCount(), equalTo((long) nbDocs));
assertNotNull(indexStatsMarvelDoc.getStore());
assertThat(indexStatsMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L));
assertNotNull(indexStatsMarvelDoc.getIndexing());
assertThat(indexStatsMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L));
}
@Test
public void testIndexStatsCollectorMultipleIndices() throws Exception {
int nbIndices = randomIntBetween(1, 5);
int[] docsPerIndex = new int[nbIndices];
for (int i = 0; i < nbIndices; i++) {
docsPerIndex[i] = randomIntBetween(1, 20);
for (int j = 0; j < docsPerIndex[i]; j++) {
client().prepareIndex("test-" + i, "test").setSource("num", i).get();
}
}
String clusterName = client().admin().cluster().prepareHealth().get().getClusterName();
client().admin().indices().prepareRefresh().get();
for (int i = 0; i < nbIndices; i++) {
assertHitCount(client().prepareCount("test-" + i).get(), docsPerIndex[i]);
}
Collection<MarvelDoc> results = newIndexStatsCollector().doCollect();
assertThat(results, hasSize(nbIndices));
for (int i = 0; i < nbIndices; i++) {
boolean found = false;
Iterator<MarvelDoc> it = results.iterator();
while (!found && it.hasNext()) {
MarvelDoc marvelDoc = it.next();
assertThat(marvelDoc, instanceOf(IndexStatsMarvelDoc.class));
IndexStatsMarvelDoc indexStatsMarvelDoc = (IndexStatsMarvelDoc) marvelDoc;
if (indexStatsMarvelDoc.getIndex().equals("test-" + i)) {
assertThat(indexStatsMarvelDoc.clusterName(), equalTo(clusterName));
assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE));
assertNotNull(indexStatsMarvelDoc.getDocs());
assertThat(indexStatsMarvelDoc.getDocs().getCount(), equalTo((long) docsPerIndex[i]));
assertNotNull(indexStatsMarvelDoc.getStore());
assertThat(indexStatsMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexStatsMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L));
assertNotNull(indexStatsMarvelDoc.getIndexing());
assertThat(indexStatsMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L));
found = true;
}
}
assertThat("could not find collected stats for index [test-" + i + "]", found, is(true));
}
}
private IndexStatsCollector newIndexStatsCollector() {
return new IndexStatsCollector(getInstanceFromNode(Settings.class), getInstanceFromNode(ClusterService.class), getInstanceFromNode(ClusterName.class), client());
}
}

View File

@ -10,7 +10,7 @@ import org.junit.Test;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class IndexMarvelDocTests extends ElasticsearchTestCase { public class IndexStatsMarvelDocTests extends ElasticsearchTestCase {
@Test @Test
public void testCreateMarvelDoc() { public void testCreateMarvelDoc() {
@ -23,7 +23,7 @@ public class IndexMarvelDocTests extends ElasticsearchTestCase {
long storeThrottle = randomLong(); long storeThrottle = randomLong();
long indexingThrottle = randomLong(); long indexingThrottle = randomLong();
IndexMarvelDoc marvelDoc = IndexMarvelDoc.createMarvelDoc(cluster, type, timestamp, IndexStatsMarvelDoc marvelDoc = IndexStatsMarvelDoc.createMarvelDoc(cluster, type, timestamp,
index, docsCount, storeSize, storeThrottle, indexingThrottle); index, docsCount, storeSize, storeThrottle, indexingThrottle);
assertNotNull(marvelDoc); assertNotNull(marvelDoc);

View File

@ -12,7 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.AgentService; import org.elasticsearch.marvel.agent.AgentService;
import org.elasticsearch.marvel.agent.collector.indices.IndexMarvelDoc; import org.elasticsearch.marvel.agent.collector.indices.IndexStatsMarvelDoc;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
@ -224,7 +224,7 @@ public class HttpESExporterTests extends ElasticsearchIntegrationTest {
final static AtomicLong timeStampGenerator = new AtomicLong(); final static AtomicLong timeStampGenerator = new AtomicLong();
private MarvelDoc newRandomMarvelDoc() { private MarvelDoc newRandomMarvelDoc() {
return IndexMarvelDoc.createMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(), return IndexStatsMarvelDoc.createMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(),
"test_index", randomInt(), randomLong(), randomLong(), randomLong()); "test_index", randomInt(), randomLong(), randomLong(), randomLong());
} }
} }