Search in sources :

Example 6 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class RestIndicesActionTests method randomIndicesStatsResponse.

private IndicesStatsResponse randomIndicesStatsResponse(final Index[] indices) {
    List<ShardStats> shardStats = new ArrayList<>();
    for (final Index index : indices) {
        for (int i = 0; i < 2; i++) {
            ShardId shardId = new ShardId(index, i);
            Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve(String.valueOf(i));
            ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, i == 0, i == 0 ? StoreRecoverySource.EMPTY_STORE_INSTANCE : PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
            shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
            shardRouting = shardRouting.moveToStarted();
            CommonStats stats = new CommonStats();
            stats.fieldData = new FieldDataStats();
            stats.queryCache = new QueryCacheStats();
            stats.docs = new DocsStats();
            stats.store = new StoreStats();
            stats.indexing = new IndexingStats();
            stats.search = new SearchStats();
            stats.segments = new SegmentsStats();
            stats.merge = new MergeStats();
            stats.refresh = new RefreshStats();
            stats.completion = new CompletionStats();
            stats.requestCache = new RequestCacheStats();
            stats.get = new GetStats();
            stats.flush = new FlushStats();
            stats.warmer = new WarmerStats();
            shardStats.add(new ShardStats(shardRouting, new ShardPath(false, path, path, shardId), stats, null, null));
        }
    }
    return IndicesStatsTests.newIndicesStatsResponse(shardStats.toArray(new ShardStats[shardStats.size()]), shardStats.size(), shardStats.size(), 0, emptyList());
}
Also used : StoreStats(org.elasticsearch.index.store.StoreStats) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RefreshStats(org.elasticsearch.index.refresh.RefreshStats) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) GetStats(org.elasticsearch.index.get.GetStats) SegmentsStats(org.elasticsearch.index.engine.SegmentsStats) ShardId(org.elasticsearch.index.shard.ShardId) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) FlushStats(org.elasticsearch.index.flush.FlushStats) ShardPath(org.elasticsearch.index.shard.ShardPath) QueryCacheStats(org.elasticsearch.index.cache.query.QueryCacheStats) DocsStats(org.elasticsearch.index.shard.DocsStats) FieldDataStats(org.elasticsearch.index.fielddata.FieldDataStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) IndexingStats(org.elasticsearch.index.shard.IndexingStats) WarmerStats(org.elasticsearch.index.warmer.WarmerStats) SearchStats(org.elasticsearch.index.search.stats.SearchStats) MergeStats(org.elasticsearch.index.merge.MergeStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RequestCacheStats(org.elasticsearch.index.cache.request.RequestCacheStats) CompletionStats(org.elasticsearch.search.suggest.completion.CompletionStats)

Example 7 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class ClusterStatsNodeResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    if (clusterStatus == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeByte(clusterStatus.value());
    }
    nodeInfo.writeTo(out);
    nodeStats.writeTo(out);
    out.writeVInt(shardsStats.length);
    for (ShardStats ss : shardsStats) {
        ss.writeTo(out);
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats)

Example 8 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), indexShard.commitStats(), indexShard.seqNoStats()));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) IndexService(org.elasticsearch.index.IndexService) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList)

Example 9 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class RestShardsAction method buildTable.

private Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsResponse stats) {
    Table table = getTableWithHeader(request);
    for (ShardRouting shard : state.getState().routingTable().allShards()) {
        ShardStats shardStats = stats.asMap().get(shard);
        CommonStats commonStats = null;
        CommitStats commitStats = null;
        if (shardStats != null) {
            commonStats = shardStats.getStats();
            commitStats = shardStats.getCommitStats();
        }
        table.startRow();
        table.addCell(shard.getIndexName());
        table.addCell(shard.id());
        IndexMetaData indexMeta = state.getState().getMetaData().getIndexSafe(shard.index());
        boolean usesShadowReplicas = false;
        if (indexMeta != null) {
            usesShadowReplicas = indexMeta.isIndexUsingShadowReplicas();
        }
        if (shard.primary()) {
            table.addCell("p");
        } else {
            if (usesShadowReplicas) {
                table.addCell("s");
            } else {
                table.addCell("r");
            }
        }
        table.addCell(shard.state());
        table.addCell(commonStats == null ? null : commonStats.getDocs().getCount());
        table.addCell(commonStats == null ? null : commonStats.getStore().getSize());
        if (shard.assignedToNode()) {
            String ip = state.getState().nodes().get(shard.currentNodeId()).getHostAddress();
            String nodeId = shard.currentNodeId();
            StringBuilder name = new StringBuilder();
            name.append(state.getState().nodes().get(shard.currentNodeId()).getName());
            if (shard.relocating()) {
                String reloIp = state.getState().nodes().get(shard.relocatingNodeId()).getHostAddress();
                String reloNme = state.getState().nodes().get(shard.relocatingNodeId()).getName();
                String reloNodeId = shard.relocatingNodeId();
                name.append(" -> ");
                name.append(reloIp);
                name.append(" ");
                name.append(reloNodeId);
                name.append(" ");
                name.append(reloNme);
            }
            table.addCell(ip);
            table.addCell(nodeId);
            table.addCell(name);
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        table.addCell(commitStats == null ? null : commitStats.getUserData().get(Engine.SYNC_COMMIT_ID));
        if (shard.unassignedInfo() != null) {
            table.addCell(shard.unassignedInfo().getReason());
            table.addCell(UnassignedInfo.DATE_TIME_FORMATTER.printer().print(shard.unassignedInfo().getUnassignedTimeInMillis()));
            table.addCell(TimeValue.timeValueMillis(System.currentTimeMillis() - shard.unassignedInfo().getUnassignedTimeInMillis()));
            table.addCell(shard.unassignedInfo().getDetails());
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        if (shard.recoverySource() != null) {
            table.addCell(shard.recoverySource().getType().toString().toLowerCase(Locale.ROOT));
        } else {
            table.addCell(null);
        }
        table.addCell(commonStats == null ? null : commonStats.getCompletion().getSize());
        table.addCell(commonStats == null ? null : commonStats.getFieldData().getMemorySize());
        table.addCell(commonStats == null ? null : commonStats.getFieldData().getEvictions());
        table.addCell(commonStats == null ? null : commonStats.getQueryCache().getMemorySize());
        table.addCell(commonStats == null ? null : commonStats.getQueryCache().getEvictions());
        table.addCell(commonStats == null ? null : commonStats.getFlush().getTotal());
        table.addCell(commonStats == null ? null : commonStats.getFlush().getTotalTime());
        table.addCell(commonStats == null ? null : commonStats.getGet().current());
        table.addCell(commonStats == null ? null : commonStats.getGet().getTime());
        table.addCell(commonStats == null ? null : commonStats.getGet().getCount());
        table.addCell(commonStats == null ? null : commonStats.getGet().getExistsTime());
        table.addCell(commonStats == null ? null : commonStats.getGet().getExistsCount());
        table.addCell(commonStats == null ? null : commonStats.getGet().getMissingTime());
        table.addCell(commonStats == null ? null : commonStats.getGet().getMissingCount());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getDeleteCurrent());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getDeleteTime());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getDeleteCount());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getIndexCurrent());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getIndexTime());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getIndexCount());
        table.addCell(commonStats == null ? null : commonStats.getIndexing().getTotal().getIndexFailedCount());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getCurrent());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getCurrentNumDocs());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getCurrentSize());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getTotal());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getTotalNumDocs());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getTotalSize());
        table.addCell(commonStats == null ? null : commonStats.getMerge().getTotalTime());
        table.addCell(commonStats == null ? null : commonStats.getRefresh().getTotal());
        table.addCell(commonStats == null ? null : commonStats.getRefresh().getTotalTime());
        table.addCell(commonStats == null ? null : commonStats.getRefresh().getListeners());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getFetchCurrent());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getFetchTime());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getFetchCount());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getOpenContexts());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getQueryCurrent());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getQueryTime());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getQueryCount());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getScrollCurrent());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getScrollTime());
        table.addCell(commonStats == null ? null : commonStats.getSearch().getTotal().getScrollCount());
        table.addCell(commonStats == null ? null : commonStats.getSegments().getCount());
        table.addCell(commonStats == null ? null : commonStats.getSegments().getMemory());
        table.addCell(commonStats == null ? null : commonStats.getSegments().getIndexWriterMemory());
        table.addCell(commonStats == null ? null : commonStats.getSegments().getVersionMapMemory());
        table.addCell(commonStats == null ? null : commonStats.getSegments().getBitsetMemory());
        table.addCell(shardStats == null || shardStats.getSeqNoStats() == null ? null : shardStats.getSeqNoStats().getMaxSeqNo());
        table.addCell(shardStats == null || shardStats.getSeqNoStats() == null ? null : shardStats.getSeqNoStats().getLocalCheckpoint());
        table.addCell(commitStats == null || shardStats.getSeqNoStats() == null ? null : shardStats.getSeqNoStats().getGlobalCheckpoint());
        table.addCell(commonStats == null ? null : commonStats.getWarmer().current());
        table.addCell(commonStats == null ? null : commonStats.getWarmer().total());
        table.addCell(commonStats == null ? null : commonStats.getWarmer().totalTime());
        table.endRow();
    }
    return table;
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) Table(org.elasticsearch.common.Table) CommitStats(org.elasticsearch.index.engine.CommitStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 10 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class DiskUsageTests method testFillShardLevelInfo.

public void testFillShardLevelInfo() {
    final Index index = new Index("test", "0xdeadbeef");
    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_0 = ShardRoutingHelper.initialize(test_0, "node1");
    test_0 = ShardRoutingHelper.moveToStarted(test_0);
    Path test0Path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("0");
    CommonStats commonStats0 = new CommonStats();
    commonStats0.store = new StoreStats(100);
    ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(index, 1), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_1 = ShardRoutingHelper.initialize(test_1, "node2");
    test_1 = ShardRoutingHelper.moveToStarted(test_1);
    Path test1Path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("1");
    CommonStats commonStats1 = new CommonStats();
    commonStats1.store = new StoreStats(1000);
    ShardStats[] stats = new ShardStats[] { new ShardStats(test_0, new ShardPath(false, test0Path, test0Path, test_0.shardId()), commonStats0, null, null), new ShardStats(test_1, new ShardPath(false, test1Path, test1Path, test_1.shardId()), commonStats1, null, null) };
    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<ShardRouting, String> routingToPath = ImmutableOpenMap.builder();
    ClusterState state = ClusterState.builder(new ClusterName("blarg")).version(0).build();
    InternalClusterInfoService.buildShardLevelInfo(logger, stats, shardSizes, routingToPath, state);
    assertEquals(2, shardSizes.size());
    assertTrue(shardSizes.containsKey(ClusterInfo.shardIdentifierFromRouting(test_0)));
    assertTrue(shardSizes.containsKey(ClusterInfo.shardIdentifierFromRouting(test_1)));
    assertEquals(100L, shardSizes.get(ClusterInfo.shardIdentifierFromRouting(test_0)).longValue());
    assertEquals(1000L, shardSizes.get(ClusterInfo.shardIdentifierFromRouting(test_1)).longValue());
    assertEquals(2, routingToPath.size());
    assertTrue(routingToPath.containsKey(test_0));
    assertTrue(routingToPath.containsKey(test_1));
    assertEquals(test0Path.getParent().getParent().getParent().toAbsolutePath().toString(), routingToPath.get(test_0));
    assertEquals(test1Path.getParent().getParent().getParent().toAbsolutePath().toString(), routingToPath.get(test_1));
}
Also used : Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) StoreStats(org.elasticsearch.index.store.StoreStats) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Index(org.elasticsearch.index.Index) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)19 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)7 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)7 ShardId (org.elasticsearch.index.shard.ShardId)6 Index (org.elasticsearch.index.Index)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 IndexShardStats (org.elasticsearch.action.admin.indices.stats.IndexShardStats)3 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)2 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2