Search in sources :

Example 1 with IndexStats

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();
}
Also used : IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Example 2 with IndexStats

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;
        }
    };
}
Also used : IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) MessageFormat(java.text.MessageFormat) Nullable(javax.annotation.Nullable)

Example 3 with IndexStats

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);
}
Also used : DeflectorSummary(org.graylog2.rest.models.system.deflector.responses.DeflectorSummary) IndexerOverview(org.graylog2.rest.models.system.indexer.responses.IndexerOverview) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) DeflectorSummary(org.graylog2.rest.models.system.deflector.responses.DeflectorSummary) IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) IndexSummary(org.graylog2.rest.models.system.indexer.responses.IndexSummary) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DeflectorResource(org.graylog2.rest.resources.system.DeflectorResource) Cluster(org.graylog2.indexer.cluster.Cluster) RestResource(org.graylog2.shared.rest.resources.RestResource) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) List(java.util.List) IndexSizeSummary(org.graylog2.rest.models.system.indexer.responses.IndexSizeSummary) IndexerClusterOverview(org.graylog2.rest.models.system.indexer.responses.IndexerClusterOverview) IndexRangesResource(org.graylog2.rest.resources.system.IndexRangesResource) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) CountResource(org.graylog2.rest.resources.count.CountResource) IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Map(java.util.Map) IndexSummary(org.graylog2.rest.models.system.indexer.responses.IndexSummary)

Example 4 with IndexStats

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);
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting)

Example 5 with IndexStats

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);
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.graylog2.rest.models.system.indexer.responses.IndexStats) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Set(java.util.Set) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) AuditEventTypes(org.graylog2.audit.AuditEventTypes) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Inject(javax.inject.Inject) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Cluster(org.graylog2.indexer.cluster.Cluster) ForbiddenException(javax.ws.rs.ForbiddenException) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) RestResource(org.graylog2.shared.rest.resources.RestResource) ApiResponse(io.swagger.annotations.ApiResponse) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

IndexStatistics (org.graylog2.indexer.indices.IndexStatistics)4 Timed (com.codahale.metrics.annotation.Timed)3 ImmutableList (com.google.common.collect.ImmutableList)3 ApiOperation (io.swagger.annotations.ApiOperation)3 GET (javax.ws.rs.GET)3 NotFoundException (javax.ws.rs.NotFoundException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ShardRouting (org.graylog2.rest.models.system.indexer.responses.ShardRouting)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 PathParam (javax.ws.rs.PathParam)2 MediaType (javax.ws.rs.core.MediaType)2 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)2 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)2 IndexSet (org.graylog2.indexer.IndexSet)2