Search in sources :

Example 1 with CommonStatsFlags

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

the class IndexShardTests method testShardStats.

public void testShardStats() throws IOException {
    IndexShard shard = newStartedShard();
    ShardStats stats = new ShardStats(shard.routingEntry(), shard.shardPath(), new CommonStats(new IndicesQueryCache(Settings.EMPTY), shard, new CommonStatsFlags()), shard.commitStats(), shard.seqNoStats());
    assertEquals(shard.shardPath().getRootDataPath().toString(), stats.getDataPath());
    assertEquals(shard.shardPath().getRootStatePath().toString(), stats.getStatePath());
    assertEquals(shard.shardPath().isCustomDataPath(), stats.isCustomDataPath());
    if (randomBoolean() || true) {
        // try to serialize it to ensure values survive the serialization
        BytesStreamOutput out = new BytesStreamOutput();
        stats.writeTo(out);
        StreamInput in = out.bytes().streamInput();
        stats = ShardStats.readShardStats(in);
    }
    XContentBuilder builder = jsonBuilder();
    builder.startObject();
    stats.toXContent(builder, EMPTY_PARAMS);
    builder.endObject();
    String xContent = builder.string();
    StringBuilder expectedSubSequence = new StringBuilder("\"shard_path\":{\"state_path\":\"");
    expectedSubSequence.append(shard.shardPath().getRootStatePath().toString());
    expectedSubSequence.append("\",\"data_path\":\"");
    expectedSubSequence.append(shard.shardPath().getRootDataPath().toString());
    expectedSubSequence.append("\",\"is_custom_data_path\":").append(shard.shardPath().isCustomDataPath()).append("}");
    if (Constants.WINDOWS) {
    // Some path weirdness on windows
    } else {
        assertTrue(xContent.contains(expectedSubSequence));
    }
    closeShards(shard);
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Matchers.containsString(org.hamcrest.Matchers.containsString) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with CommonStatsFlags

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

the class NodesStatsRequest method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    indices = new CommonStatsFlags(in);
    os = in.readBoolean();
    process = in.readBoolean();
    jvm = in.readBoolean();
    threadPool = in.readBoolean();
    fs = in.readBoolean();
    transport = in.readBoolean();
    http = in.readBoolean();
    breaker = in.readBoolean();
    script = in.readBoolean();
    discovery = in.readBoolean();
    ingest = in.readBoolean();
}
Also used : CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags)

Example 3 with CommonStatsFlags

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

the class RestAllocationAction method doCatRequest.

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

        @Override
        public void processResponse(final ClusterStateResponse state) {
            NodesStatsRequest statsRequest = new NodesStatsRequest(nodes);
            statsRequest.clear().fs(true).indices(new CommonStatsFlags(CommonStatsFlags.Flag.Store));
            client.admin().cluster().nodesStats(statsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                @Override
                public RestResponse buildResponse(NodesStatsResponse stats) throws Exception {
                    Table tab = buildTable(request, state, stats);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) ObjectIntScatterMap(com.carrotsearch.hppc.ObjectIntScatterMap) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) NodeClient(org.elasticsearch.client.node.NodeClient) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) Table(org.elasticsearch.common.Table) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)

Example 4 with CommonStatsFlags

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

the class RestNodesStatsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));
    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(nodesIds);
    nodesStatsRequest.timeout(request.param("timeout"));
    if (metrics.size() == 1 && metrics.contains("_all")) {
        if (request.hasParam("index_metric")) {
            throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains index metrics [%s] but all stats requested", request.path(), request.param("index_metric")));
        }
        nodesStatsRequest.all();
        nodesStatsRequest.indices(CommonStatsFlags.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 {
        nodesStatsRequest.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<NodesStatsRequest> handler = METRICS.get(metric);
            if (handler != null) {
                handler.accept(nodesStatsRequest);
            } else {
                invalidMetrics.add(metric);
            }
        }
        if (!invalidMetrics.isEmpty()) {
            throw new IllegalArgumentException(unrecognized(request, invalidMetrics, METRICS.keySet(), "metric"));
        }
        // check for index specific metrics
        if (metrics.contains("indices")) {
            Set<String> indexMetrics = Strings.splitStringByCommaToSet(request.param("index_metric", "_all"));
            if (indexMetrics.size() == 1 && indexMetrics.contains("_all")) {
                nodesStatsRequest.indices(CommonStatsFlags.ALL);
            } else {
                CommonStatsFlags flags = new CommonStatsFlags();
                flags.clear();
                // use a sorted set so the unrecognized parameters appear in a reliable sorted order
                final Set<String> invalidIndexMetrics = new TreeSet<>();
                for (final String indexMetric : indexMetrics) {
                    final Consumer<CommonStatsFlags> handler = FLAGS.get(indexMetric);
                    if (handler != null) {
                        handler.accept(flags);
                    } else {
                        invalidIndexMetrics.add(indexMetric);
                    }
                }
                if (!invalidIndexMetrics.isEmpty()) {
                    throw new IllegalArgumentException(unrecognized(request, invalidIndexMetrics, FLAGS.keySet(), "index metric"));
                }
                nodesStatsRequest.indices(flags);
            }
        } else if (request.hasParam("index_metric")) {
            throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains index metrics [%s] but indices stats not requested", request.path(), request.param("index_metric")));
        }
    }
    if (nodesStatsRequest.indices().isSet(Flag.FieldData) && (request.hasParam("fields") || request.hasParam("fielddata_fields"))) {
        nodesStatsRequest.indices().fieldDataFields(request.paramAsStringArray("fielddata_fields", request.paramAsStringArray("fields", null)));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Completion) && (request.hasParam("fields") || request.hasParam("completion_fields"))) {
        nodesStatsRequest.indices().completionDataFields(request.paramAsStringArray("completion_fields", request.paramAsStringArray("fields", null)));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Search) && (request.hasParam("groups"))) {
        nodesStatsRequest.indices().groups(request.paramAsStringArray("groups", null));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Indexing) && (request.hasParam("types"))) {
        nodesStatsRequest.indices().types(request.paramAsStringArray("types", null));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Segments)) {
        nodesStatsRequest.indices().includeSegmentFileSizes(request.paramAsBoolean("include_segment_file_sizes", false));
    }
    return channel -> client.admin().cluster().nodesStats(nodesStatsRequest, new NodesResponseRestListener<>(channel));
}
Also used : NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) RestController(org.elasticsearch.rest.RestController) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) TreeSet(java.util.TreeSet) Strings(org.elasticsearch.common.Strings) Consumer(java.util.function.Consumer) NodesResponseRestListener(org.elasticsearch.rest.action.RestActions.NodesResponseRestListener) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) NodeClient(org.elasticsearch.client.node.NodeClient) Collections(java.util.Collections) Set(java.util.Set) TreeSet(java.util.TreeSet) Consumer(java.util.function.Consumer) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags)

Example 5 with CommonStatsFlags

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

the class InternalTestCluster method ensureEstimatedStats.

@Override
public void ensureEstimatedStats() {
    if (size() > 0) {
        // of the breakers
        for (NodeAndClient nodeAndClient : nodes.values()) {
            final IndicesFieldDataCache fdCache = getInstanceFromNode(IndicesService.class, nodeAndClient.node).getIndicesFieldDataCache();
            // Clean up the cache, ensuring that entries' listeners have been called
            fdCache.getCache().refresh();
            final String name = nodeAndClient.name;
            final CircuitBreakerService breakerService = getInstanceFromNode(CircuitBreakerService.class, nodeAndClient.node);
            CircuitBreaker fdBreaker = breakerService.getBreaker(CircuitBreaker.FIELDDATA);
            assertThat("Fielddata breaker not reset to 0 on node: " + name, fdBreaker.getUsed(), equalTo(0L));
            // fail if it never reached 0
            try {
                assertBusy(new Runnable() {

                    @Override
                    public void run() {
                        CircuitBreaker reqBreaker = breakerService.getBreaker(CircuitBreaker.REQUEST);
                        assertThat("Request breaker not reset to 0 on node: " + name, reqBreaker.getUsed(), equalTo(0L));
                    }
                });
            } catch (Exception e) {
                fail("Exception during check for request breaker reset to 0: " + e);
            }
            NodeService nodeService = getInstanceFromNode(NodeService.class, nodeAndClient.node);
            CommonStatsFlags flags = new CommonStatsFlags(Flag.FieldData, Flag.QueryCache, Flag.Segments);
            NodeStats stats = nodeService.stats(flags, false, false, false, false, false, false, false, false, false, false, false);
            assertThat("Fielddata size must be 0 on node: " + stats.getNode(), stats.getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
            assertThat("Query cache size must be 0 on node: " + stats.getNode(), stats.getIndices().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
            assertThat("FixedBitSet cache size must be 0 on node: " + stats.getNode(), stats.getIndices().getSegments().getBitsetMemoryInBytes(), equalTo(0L));
        }
    }
}
Also used : IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) NodeService(org.elasticsearch.node.NodeService) IndicesService(org.elasticsearch.indices.IndicesService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeValidationException(org.elasticsearch.node.NodeValidationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Aggregations

CommonStatsFlags (org.elasticsearch.action.admin.indices.stats.CommonStatsFlags)8 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)3 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)3 IOException (java.io.IOException)2 NodesStatsRequest (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)2 Flag (org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 Strings (org.elasticsearch.common.Strings)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)2 Settings (org.elasticsearch.common.settings.Settings)2 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)2 IndicesService (org.elasticsearch.indices.IndicesService)2 RestController (org.elasticsearch.rest.RestController)2 RestRequest (org.elasticsearch.rest.RestRequest)2 GET (org.elasticsearch.rest.RestRequest.Method.GET)2 ObjectIntScatterMap (com.carrotsearch.hppc.ObjectIntScatterMap)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1