Search in sources :

Example 1 with IndicesStatsRequest

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

the class RestIndicesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().indices(indices).metaData(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final IndicesOptions strictExpandIndicesOptions = IndicesOptions.strictExpand();
    clusterStateRequest.indicesOptions(strictExpandIndicesOptions);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final ClusterState state = clusterStateResponse.getState();
            final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, strictExpandIndicesOptions, indices);
            assert concreteIndices.length == state.metaData().getIndices().size();
            ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices);
            clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
            client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

                @Override
                public void processResponse(final ClusterHealthResponse clusterHealthResponse) {
                    IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
                    indicesStatsRequest.indices(indices);
                    indicesStatsRequest.indicesOptions(strictExpandIndicesOptions);
                    indicesStatsRequest.all();
                    client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                            Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse, state.metaData());
                            return RestTable.buildResponse(tab, channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) GET(org.elasticsearch.rest.RestRequest.Method.GET) Table(org.elasticsearch.common.Table) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Index(org.elasticsearch.index.Index) ClusterIndexHealth(org.elasticsearch.cluster.health.ClusterIndexHealth) Strings(org.elasticsearch.common.Strings) HashSet(java.util.HashSet) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) RestResponse(org.elasticsearch.rest.RestResponse) DateTime(org.joda.time.DateTime) Set(java.util.Set) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Collections(java.util.Collections) RestActionListener(org.elasticsearch.rest.action.RestActionListener) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) Table(org.elasticsearch.common.Table) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.elasticsearch.rest.action.RestActionListener) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 2 with IndicesStatsRequest

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

the class RestShardsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
            indicesStatsRequest.all();
            indicesStatsRequest.indices(indices);
            client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {

                @Override
                public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
                }
            });
        }
    });
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) CommitStats(org.elasticsearch.index.engine.CommitStats) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) Engine(org.elasticsearch.index.engine.Engine) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Locale(java.util.Locale) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 3 with IndicesStatsRequest

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest in project graylog2-server by Graylog2.

the class Indices method indexStats.

@Nullable
public IndexStats indexStats(final String indexName) {
    final IndicesStatsRequest request = c.admin().indices().prepareStats(indexName).request();
    final IndicesStatsResponse response = c.admin().indices().stats(request).actionGet();
    return response.getIndex(indexName);
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Nullable(javax.annotation.Nullable)

Example 4 with IndicesStatsRequest

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

the class RestIndicesStatsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
    indicesStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesStatsRequest.indicesOptions()));
    indicesStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
    indicesStatsRequest.types(Strings.splitStringByCommaToArray(request.param("types")));
    Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));
    // short cut, if no metrics have been specified in URI
    if (metrics.size() == 1 && metrics.contains("_all")) {
        indicesStatsRequest.all();
    } else if (metrics.contains("_all")) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]", request.path(), request.param("metric")));
    } else {
        indicesStatsRequest.clear();
        // use a sorted set so the unrecognized parameters appear in a reliable sorted order
        final Set<String> invalidMetrics = new TreeSet<>();
        for (final String metric : metrics) {
            final Consumer<IndicesStatsRequest> consumer = METRICS.get(metric);
            if (consumer != null) {
                consumer.accept(indicesStatsRequest);
            } else {
                invalidMetrics.add(metric);
            }
        }
        if (!invalidMetrics.isEmpty()) {
            throw new IllegalArgumentException(unrecognized(request, invalidMetrics, METRICS.keySet(), "metric"));
        }
    }
    if (request.hasParam("groups")) {
        indicesStatsRequest.groups(Strings.splitStringByCommaToArray(request.param("groups")));
    }
    if (request.hasParam("types")) {
        indicesStatsRequest.types(Strings.splitStringByCommaToArray(request.param("types")));
    }
    if (indicesStatsRequest.completion() && (request.hasParam("fields") || request.hasParam("completion_fields"))) {
        indicesStatsRequest.completionFields(request.paramAsStringArray("completion_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY)));
    }
    if (indicesStatsRequest.fieldData() && (request.hasParam("fields") || request.hasParam("fielddata_fields"))) {
        indicesStatsRequest.fieldDataFields(request.paramAsStringArray("fielddata_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY)));
    }
    if (indicesStatsRequest.segments()) {
        indicesStatsRequest.includeSegmentFileSizes(request.paramAsBoolean("include_segment_file_sizes", false));
    }
    return channel -> client.admin().indices().stats(indicesStatsRequest, new RestBuilderListener<IndicesStatsResponse>(channel) {

        @Override
        public RestResponse buildResponse(IndicesStatsResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) TreeSet(java.util.TreeSet) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Consumer(java.util.function.Consumer) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) RestActions.buildBroadcastShardsHeader(org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader) Locale(java.util.Locale) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) Collections(java.util.Collections) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) Set(java.util.Set) TreeSet(java.util.TreeSet) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IOException(java.io.IOException) Consumer(java.util.function.Consumer) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 5 with IndicesStatsRequest

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

the class IndicesRequestIT method testIndicesStats.

public void testIndicesStats() {
    String indicesStats = IndicesStatsAction.NAME + "[n]";
    interceptTransportActions(indicesStats);
    IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest().indices(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().stats(indicesStatsRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(indicesStatsRequest, indicesStats);
}
Also used : IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Aggregations

IndicesStatsRequest (org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)9 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)7 Locale (java.util.Locale)3 NodeClient (org.elasticsearch.client.node.NodeClient)3 Strings (org.elasticsearch.common.Strings)3 Settings (org.elasticsearch.common.settings.Settings)3 RestController (org.elasticsearch.rest.RestController)3 RestRequest (org.elasticsearch.rest.RestRequest)3 GET (org.elasticsearch.rest.RestRequest.Method.GET)3 RestResponse (org.elasticsearch.rest.RestResponse)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)2 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)2 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 Table (org.elasticsearch.common.Table)2 RestActionListener (org.elasticsearch.rest.action.RestActionListener)2