Search in sources :

Example 1 with IndexStatistics

use of org.graylog2.indexer.indices.stats.IndexStatistics in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyTest method testDontRotate.

@Test
public void testDontRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100000L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, never()).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 2 with IndexStatistics

use of org.graylog2.indexer.indices.stats.IndexStatistics in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyTest method testRotate.

@Test
public void testRotate() throws Exception {
    final CommonStats commonStats = new CommonStats();
    commonStats.store = new StoreStats(1000, 0);
    final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
    when(indices.getIndexStats("name")).thenReturn(stats);
    when(indexSet.getNewestIndex()).thenReturn("name");
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100L));
    final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
    strategy.rotate(indexSet);
    verify(indexSet, times(1)).cycle();
    reset(indexSet);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) StoreStats(org.elasticsearch.index.store.StoreStats) Test(org.junit.Test)

Example 3 with IndexStatistics

use of org.graylog2.indexer.indices.stats.IndexStatistics in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method indicesStats.

@Override
public Set<IndexStatistics> indicesStats(Collection<String> indices) {
    final ImmutableSet.Builder<IndexStatistics> result = ImmutableSet.builder();
    final JsonNode allWithShardLevel = statsApi.indexStatsWithShardLevel(indices);
    final Iterator<Map.Entry<String, JsonNode>> fields = allWithShardLevel.fields();
    while (fields.hasNext()) {
        final Map.Entry<String, JsonNode> entry = fields.next();
        final String index = entry.getKey();
        final JsonNode indexStats = entry.getValue();
        if (indexStats.isObject()) {
            result.add(IndexStatistics.create(index, indexStats));
        }
    }
    return result.build();
}
Also used : IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) ImmutableSet(com.google.common.collect.ImmutableSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 4 with IndexStatistics

use of org.graylog2.indexer.indices.stats.IndexStatistics in project graylog2-server by Graylog2.

the class IndicesResource method toIndexInfos.

private Map<String, IndexInfo> toIndexInfos(Collection<IndexStatistics> indexStatistics) {
    final Set<String> indexNames = indexStatistics.stream().map(IndexStatistics::index).collect(Collectors.toSet());
    final Map<String, Boolean> reopenedStatus = indices.areReopened(indexNames);
    final ImmutableMap.Builder<String, IndexInfo> indexInfos = ImmutableMap.builder();
    for (IndexStatistics indexStats : indexStatistics) {
        final IndexInfo indexInfo = IndexInfo.create(indexStats.primaryShards(), indexStats.allShards(), fillShardRoutings(indexStats.routing()), reopenedStatus.getOrDefault(indexStats.index(), false));
        indexInfos.put(indexStats.index(), indexInfo);
    }
    return indexInfos.build();
}
Also used : IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with IndexStatistics

use of org.graylog2.indexer.indices.stats.IndexStatistics in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method globalStats.

@Test
public void globalStats() throws Exception {
    final IndexStatistics indexStatistics = IndexStatistics.create("prefix_0", IndexStats.create(IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), 0L, 23L, 2L, IndexStats.DocsStats.create(42L, 0L)), IndexStats.create(IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), IndexStats.TimeAndTotalStats.create(0L, 0L), 0L, 23L, 2L, IndexStats.DocsStats.create(42L, 0L)), Collections.emptyList());
    when(indices.getClosedIndices(anyCollection())).thenReturn(Collections.singleton("closed_index_0"));
    when(indices.getIndicesStats(anyCollection())).thenReturn(Collections.singleton(indexStatistics));
    final IndexSetStats indexSetStats = indexSetsResource.globalStats();
    assertThat(indexSetStats).isNotNull();
    assertThat(indexSetStats.indices()).isEqualTo(2L);
    assertThat(indexSetStats.documents()).isEqualTo(42L);
    assertThat(indexSetStats.size()).isEqualTo(23L);
}
Also used : IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) Test(org.junit.Test)

Aggregations

IndexStatistics (org.graylog2.indexer.indices.stats.IndexStatistics)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 IndexInfo (org.graylog2.rest.models.system.indexer.responses.IndexInfo)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)2 StoreStats (org.elasticsearch.index.store.StoreStats)2 IndexStatistics (org.graylog2.indexer.indices.IndexStatistics)2 Timed (com.codahale.metrics.annotation.Timed)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1