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

The following examples show how to use org.elasticsearch.action.admin.indices.stats.CommonStats. 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: TransportIndexShardStatsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected ShardStats shardOperation(IndexShardStatsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
    // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
    if (indexShard.routingEntry() == null) {
        throw new ShardNotFoundException(indexShard.shardId());
    }

    if (!indexShard.state().equals(IndexShardState.STARTED)) {
        throw new ElasticsearchException(indexShard.shardId().toString() + " state is " + indexShard.state() + ", not started");
    }
    
    CommonStatsFlags flags = new CommonStatsFlags().clear();

    if (request.dl()) {
        flags.set(CommonStatsFlags.Flag.DL);
    }

    return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats());
}
 
Example #2
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 #3
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 #4
Source File: TransportClusterStatsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(false, true, false, true, false, true, false, true);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, 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(indexShard, SHARD_STATS_FLAGS), indexShard.commitStats()));
            }
        }
    }

    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().localNodeMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }

    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));

}
 
Example #5
Source File: EsEntityIndexImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private long getIndexSize(){
    long indexSize = 0L;
    final String indexName = indexLocationStrategy.getIndexInitialName();
    try {
        final IndicesStatsResponse statsResponse = esProvider.getClient()
            .admin()
            .indices()
            .prepareStats(indexName)
            .all()
            .execute()
            .actionGet();
        final CommonStats indexStats = statsResponse.getIndex(indexName).getTotal();
        indexSize = indexStats.getStore().getSizeInBytes();
    } catch (IndexMissingException e) {
        // if for some reason the index size does not exist,
        // log an error and we can assume size is 0 as it doesn't exist
        logger.error("Unable to get size for index {} due to IndexMissingException for app {}",
            indexName, indexLocationStrategy.getApplicationScope().getApplication().getUuid());
    }
    return indexSize;
}
 
Example #6
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 #7
Source File: DLBasedEngine.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    try {
        if (isPrimaryInRouting) {
            ActionFuture<IndexShardStatsResponse>  result = indexShardStatsAction.execute(new IndexShardStatsRequest(shardId.index().getName(), shardId.id()));
            IndexShardStatsResponse response = result.actionGet(10000);
            if (response.getTotalShards() == response.getSuccessfulShards() && response.getTotalShards() > 0) {
                DLSN miniumDlsn = new DLSN(Long.MAX_VALUE, 0, 0);
                boolean hasInvalidShardStats = false;
                for (ShardStats shardStats : response.getShards()) {
                    boolean isInvalid = true;
                    CommonStats commonStats = shardStats.getStats();
                    if (commonStats != null) {
                        DLStats dlStats = commonStats.getDLStats();
                        if (dlStats != null && !dlStats.getCommitDlsn().equals(DLSN.InvalidDLSN)) {
                            isInvalid = false;
                            if (dlStats.getCommitDlsn().compareTo(miniumDlsn) < 0) {
                                miniumDlsn = dlStats.getCommitDlsn();
                            }
                        } else {
                            logger.debug("dl [{}] status is invalid", dlStats);
                        }
                    } else {
                        logger.debug("common stats is null");
                    }
                    if (isInvalid) {
                        hasInvalidShardStats = true;
                        break;
                    }
                }
                if (!hasInvalidShardStats) {
                    if (!miniumDlsn.equals(DLSN.InitialDLSN)) {
                        logger.info("try to truncate log before [{}]", miniumDlsn);
                        dlTranslog.truncateLogBeforeDLSN(miniumDlsn);
                    }
                }
            } else {
                logger.warn("some shards failed to get stats: total shards [{}], shards give reponse [{}], failure exceptions [{}], maybe some shard is abnormal so skip truncate log", 
                        response.getTotalShards(), 
                        response.getSuccessfulShards(),
                        response.getShardFailures().length > 0 ? response.getShardFailures()[0] : "");
            }
        }
    } catch (Throwable t) {
        logger.error("catch exception when sleep to next lease check time", t);
    } finally {
        if (!isClosed.get()) {
            // check in 1 minutes
            threadPool.schedule(TimeValue.timeValueMinutes(1), ThreadPool.Names.GENERIC, this);
        }
    }
}
 
Example #8
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);
}
 
Example #9
Source File: ClusterStatsIndices.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public ClusterStatsIndices(ClusterStatsNodeResponse[] nodeResponses) {
    ObjectObjectHashMap<String, ShardStats> countsPerIndex = new ObjectObjectHashMap<>();

    this.docs = new DocsStats();
    this.store = new StoreStats();
    this.fieldData = new FieldDataStats();
    this.queryCache = new QueryCacheStats();
    this.completion = new CompletionStats();
    this.segments = new SegmentsStats();
    this.percolate = new PercolateStats();

    for (ClusterStatsNodeResponse r : nodeResponses) {
        for (org.elasticsearch.action.admin.indices.stats.ShardStats shardStats : r.shardsStats()) {
            ShardStats indexShardStats = countsPerIndex.get(shardStats.getShardRouting().getIndex());
            if (indexShardStats == null) {
                indexShardStats = new ShardStats();
                countsPerIndex.put(shardStats.getShardRouting().getIndex(), indexShardStats);
            }

            indexShardStats.total++;

            CommonStats shardCommonStats = shardStats.getStats();

            if (shardStats.getShardRouting().primary()) {
                indexShardStats.primaries++;
                docs.add(shardCommonStats.docs);
            }
            store.add(shardCommonStats.store);
            fieldData.add(shardCommonStats.fieldData);
            queryCache.add(shardCommonStats.queryCache);
            completion.add(shardCommonStats.completion);
            segments.add(shardCommonStats.segments);
            percolate.add(shardCommonStats.percolate);
        }
    }

    shards = new ShardStats();
    indexCount = countsPerIndex.size();
    for (ObjectObjectCursor<String, ShardStats> indexCountsCursor : countsPerIndex) {
        shards.addIndexShardCount(indexCountsCursor.value);
    }
}