use of org.graylog2.rest.models.system.indexer.responses.IndexStats in project graylog2-server by Graylog2.
the class Indices method numberOfMessages.
public long numberOfMessages(String indexName) throws IndexNotFoundException {
final IndexStats index = indexStats(indexName);
if (index == null) {
throw new IndexNotFoundException("Couldn't find index " + indexName);
}
final DocsStats docsStats = index.getPrimaries().getDocs();
return docsStats == null ? 0L : docsStats.getCount();
}
use of org.graylog2.rest.models.system.indexer.responses.IndexStats in project graylog2-server by Graylog2.
the class SizeBasedRotationStrategy method shouldRotate.
@Nullable
@Override
protected Result shouldRotate(final String index, IndexSet indexSet) {
if (!(indexSet.getConfig().rotationStrategy() instanceof SizeBasedRotationStrategyConfig)) {
throw new IllegalStateException("Invalid rotation strategy config <" + indexSet.getConfig().rotationStrategy().getClass().getCanonicalName() + "> for index set <" + indexSet.getConfig().id() + ">");
}
final SizeBasedRotationStrategyConfig config = (SizeBasedRotationStrategyConfig) indexSet.getConfig().rotationStrategy();
final IndexStatistics indexStats = indices.getIndexStats(index);
if (indexStats == null) {
return null;
}
final long sizeInBytes = indexStats.primaries().getStore().getSizeInBytes();
final boolean shouldRotate = sizeInBytes > config.maxSize();
return new Result() {
public final MessageFormat ROTATE = new MessageFormat("Storage size for index <{0}> is {1} bytes, exceeding the maximum of {2} bytes. Rotating index.", Locale.ENGLISH);
public final MessageFormat NOT_ROTATE = new MessageFormat("Storage size for index <{0}> is {1} bytes, below the maximum of {2} bytes. Not doing anything.", Locale.ENGLISH);
@Override
public String getDescription() {
MessageFormat format = shouldRotate() ? ROTATE : NOT_ROTATE;
return format.format(new Object[] { index, sizeInBytes, config.maxSize() });
}
@Override
public boolean shouldRotate() {
return shouldRotate;
}
};
}
use of org.graylog2.rest.models.system.indexer.responses.IndexStats in project graylog2-server by Graylog2.
the class IndexerOverviewResource method getIndexerOverview.
private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException {
final String indexSetId = indexSet.getConfig().id();
final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId);
final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges();
final Map<String, IndexStats> allDocCounts = indices.getAllDocCounts(indexSet).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
final Map<String, Boolean> areReopened = indices.areReopened(allDocCounts.keySet());
final Map<String, IndexSummary> indicesSummaries = allDocCounts.values().stream().parallel().collect(Collectors.toMap(IndexStats::getIndex, (indexStats) -> IndexSummary.create(IndexSizeSummary.create(indexStats.getPrimaries().getDocs().getCount(), indexStats.getPrimaries().getDocs().getDeleted(), indexStats.getPrimaries().getStore().sizeInBytes()), indexRanges.stream().filter((indexRangeSummary) -> indexRangeSummary.indexName().equals(indexStats.getIndex())).findFirst().orElse(null), deflectorSummary.currentTarget() != null && deflectorSummary.currentTarget().equals(indexStats.getIndex()), false, areReopened.get(indexStats.getIndex()))));
indices.getClosedIndices(indexSet).forEach(indexName -> indicesSummaries.put(indexName, IndexSummary.create(null, indexRanges.stream().filter((indexRangeSummary) -> indexRangeSummary.indexName().equals(indexName)).findFirst().orElse(null), deflectorSummary.currentTarget() != null && deflectorSummary.currentTarget().equals(indexName), true, false)));
return IndexerOverview.create(deflectorSummary, IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()), countResource.total(indexSetId), indicesSummaries);
}
use of org.graylog2.rest.models.system.indexer.responses.IndexStats in project graylog2-server by Graylog2.
the class IndicesResource method getOpenIndicesInfo.
private OpenIndicesInfo getOpenIndicesInfo(Set<IndexStatistics> indicesStats) {
final Map<String, IndexInfo> indexInfos = new HashMap<>();
final Map<String, Boolean> areReopened = indices.areReopened(indicesStats.stream().map(IndexStatistics::indexName).collect(Collectors.toSet()));
for (IndexStatistics indexStatistics : indicesStats) {
final ImmutableList.Builder<ShardRouting> routing = ImmutableList.builder();
for (org.elasticsearch.cluster.routing.ShardRouting shardRouting : indexStatistics.shardRoutings()) {
routing.add(shardRouting(shardRouting));
}
final IndexInfo indexInfo = IndexInfo.create(indexStats(indexStatistics.primaries()), indexStats(indexStatistics.total()), routing.build(), areReopened.get(indexStatistics.indexName()));
indexInfos.put(indexStatistics.indexName(), indexInfo);
}
return OpenIndicesInfo.create(indexInfos);
}
use of org.graylog2.rest.models.system.indexer.responses.IndexStats in project graylog2-server by Graylog2.
the class IndicesResource method indexSetOpen.
@GET
@Path("/{indexSetId}/open")
@Timed
@ApiOperation(value = "Get information of all open indices managed by Graylog and their shards.")
@RequiresPermissions(RestPermissions.INDICES_READ)
@Produces(MediaType.APPLICATION_JSON)
public OpenIndicesInfo indexSetOpen(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
final Set<IndexStatistics> indicesStats = indices.getIndicesStats(indexSet).stream().filter(indexStats -> indexSetRegistry.isManagedIndex(indexStats.indexName())).collect(Collectors.toSet());
return getOpenIndicesInfo(indicesStats);
}
Aggregations