org.elasticsearch.action.admin.indices.stats.IndexShardStats Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.stats.IndexShardStats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeIndicesStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    stats = CommonStats.readCommonStats(in);
    if (in.readBoolean()) {
        int entries = in.readVInt();
        statsByShard = Maps.newHashMap();
        for (int i = 0; i < entries; i++) {
            Index index = Index.readIndexName(in);
            int indexShardListSize = in.readVInt();
            List<IndexShardStats> indexShardStats = new ArrayList<>(indexShardListSize);
            for (int j = 0; j < indexShardListSize; j++) {
                indexShardStats.add(IndexShardStats.readIndexShardStats(in));
            }
            statsByShard.put(index, indexShardStats);
        }
    }
}
 
Example #2
Source File: NodeIndicesStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Map<Index, CommonStats> createStatsByIndex() {
    Map<Index, CommonStats> statsMap = Maps.newHashMap();
    for (Map.Entry<Index, List<IndexShardStats>> entry : statsByShard.entrySet()) {
        if (!statsMap.containsKey(entry.getKey())) {
            statsMap.put(entry.getKey(), new CommonStats());
        }

        for (IndexShardStats indexShardStats : entry.getValue()) {
            for (ShardStats shardStats : indexShardStats.getShards()) {
                statsMap.get(entry.getKey()).add(shardStats.getStats());
            }
        }
    }

    return statsMap;
}
 
Example #3
Source File: NodeIndicesStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public NodeIndicesStats(CommonStats oldStats, Map<Index, List<IndexShardStats>> statsByShard) {
    //this.stats = stats;
    this.statsByShard = statsByShard;

    // make a total common stats from old ones and current ones
    this.stats = oldStats;
    for (List<IndexShardStats> shardStatsList : statsByShard.values()) {
        for (IndexShardStats indexShardStats : shardStatsList) {
            for (ShardStats shardStats : indexShardStats.getShards()) {
                stats.add(shardStats.getStats());
            }
        }
    }
}
 
Example #4
Source File: NodeIndicesStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    stats.writeTo(out);
    out.writeBoolean(statsByShard != null);
    if (statsByShard != null) {
        out.writeVInt(statsByShard.size());
        for (Map.Entry<Index, List<IndexShardStats>> entry : statsByShard.entrySet()) {
            entry.getKey().writeTo(out);
            out.writeVInt(entry.getValue().size());
            for (IndexShardStats indexShardStats : entry.getValue()) {
                indexShardStats.writeTo(out);
            }
        }
    }
}
 
Example #5
Source File: TransportResizeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(final ResizeRequest resizeRequest, final ClusterState state,
                               final ActionListener<ResizeResponse> listener) {

    // there is no need to fetch docs stats for split but we keep it simple and do it anyway for simplicity of the code
    final String sourceIndex = resizeRequest.getSourceIndex();
    final String targetIndex = resizeRequest.getTargetIndexRequest().index();
    client.admin().indices().prepareStats(sourceIndex).clear().setDocs(true).execute(new ActionListener<>() {
        @Override
        public void onResponse(IndicesStatsResponse indicesStatsResponse) {
            CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(resizeRequest, state,
                (i) -> {
                    IndexShardStats shard = indicesStatsResponse.getIndex(sourceIndex).getIndexShards().get(i);
                    return shard == null ? null : shard.getPrimary().getDocs();
                }, sourceIndex, targetIndex);
            createIndexService.createIndex(
                updateRequest,
                ActionListener.wrap(response ->
                        listener.onResponse(new ResizeResponse(response.isAcknowledged(), response.isShardsAcknowledged(),
                                updateRequest.index())), listener::onFailure
                )
            );
        }

        @Override
        public void onFailure(Exception e) {
            listener.onFailure(e);
        }
    });

}
 
Example #6
Source File: IndexShardStatsResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    String level = params.param("level", "indices");
    boolean isLevelValid = "indices".equalsIgnoreCase(level) || "shards".equalsIgnoreCase(level) || "cluster".equalsIgnoreCase(level);
    if (!isLevelValid) {
        return builder;
    }

    if ("indices".equalsIgnoreCase(level) || "shards".equalsIgnoreCase(level)) {
        builder.startObject(Fields.INDICES);
        for (IndexStats indexStats : getIndices().values()) {
            builder.startObject(indexStats.getIndex(), XContentBuilder.FieldCaseConversion.NONE);

            builder.startObject("primaries");
            indexStats.getPrimaries().toXContent(builder, params);
            builder.endObject();

            builder.startObject("total");
            indexStats.getTotal().toXContent(builder, params);
            builder.endObject();

            if ("shards".equalsIgnoreCase(level)) {
                builder.startObject(Fields.SHARDS);
                for (IndexShardStats indexShardStats : indexStats) {
                    builder.startArray(Integer.toString(indexShardStats.getShardId().id()));
                    for (ShardStats shardStats : indexShardStats) {
                        builder.startObject();
                        shardStats.toXContent(builder, params);
                        builder.endObject();
                    }
                    builder.endArray();
                }
                builder.endObject();
            }
            builder.endObject();
        }
        builder.endObject();
    }

    return builder;
}
 
Example #7
Source File: IndicesService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) {
    CommonStats oldStats = new CommonStats(flags);

    if (includePrevious) {
        Flag[] setFlags = flags.getFlags();
        for (Flag flag : setFlags) {
            switch (flag) {
                case Get:
                    oldStats.get.add(oldShardsStats.getStats);
                    break;
                case Indexing:
                    oldStats.indexing.add(oldShardsStats.indexingStats);
                    break;
                case Search:
                    oldStats.search.add(oldShardsStats.searchStats);
                    break;
                case Merge:
                    oldStats.merge.add(oldShardsStats.mergeStats);
                    break;
                case Refresh:
                    oldStats.refresh.add(oldShardsStats.refreshStats);
                    break;
                case Recovery:
                    oldStats.recoveryStats.add(oldShardsStats.recoveryStats);
                    break;
                case Flush:
                    oldStats.flush.add(oldShardsStats.flushStats);
                    break;
            }
        }
    }

    Map<Index, List<IndexShardStats>> statsByShard = Maps.newHashMap();
    for (IndexServiceInjectorPair value : indices.values()) {
        IndexService indexService = value.getIndexService();
        for (IndexShard indexShard : indexService) {
            try {
                if (indexShard.routingEntry() == null) {
                    continue;
                }
                IndexShardStats indexShardStats = new IndexShardStats(indexShard.shardId(), new ShardStats[] { new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats()) });
                if (!statsByShard.containsKey(indexService.index())) {
                    statsByShard.put(indexService.index(), arrayAsArrayList(indexShardStats));
                } else {
                    statsByShard.get(indexService.index()).add(indexShardStats);
                }
            } catch (IllegalIndexShardStateException e) {
                // we can safely ignore illegal state on ones that are closing for example
                logger.trace("{} ignoring shard stats", e, indexShard.shardId());
            }
        }
    }
    return new NodeIndicesStats(oldStats, statsByShard);
}