Search in sources :

Example 1 with NodesStatsRequest

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest 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 2 with NodesStatsRequest

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest in project elasticsearch by elastic.

the class RestFielddataAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
    nodesStatsRequest.clear();
    nodesStatsRequest.indices(true);
    String[] fields = request.paramAsStringArray("fields", null);
    nodesStatsRequest.indices().fieldDataFields(fields == null ? new String[] { "*" } : fields);
    return channel -> client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

        @Override
        public RestResponse buildResponse(NodesStatsResponse nodeStatses) throws Exception {
            return RestTable.buildResponse(buildTable(request, nodeStatses), channel);
        }
    });
}
Also used : NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) 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) Settings(org.elasticsearch.common.settings.Settings) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) ObjectLongCursor(com.carrotsearch.hppc.cursors.ObjectLongCursor) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestResponse(org.elasticsearch.rest.RestResponse)

Example 3 with NodesStatsRequest

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest in project elasticsearch by elastic.

the class RestThreadPoolAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(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 clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().process(true).threadPool(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().threadPool(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : GET(org.elasticsearch.rest.RestRequest.Method.GET) Table(org.elasticsearch.common.Table) HashMap(java.util.HashMap) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Regex(org.elasticsearch.common.regex.Regex) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) RestResponse(org.elasticsearch.rest.RestResponse) Set(java.util.Set) RestController(org.elasticsearch.rest.RestController) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) TreeMap(java.util.TreeMap) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) Collections(java.util.Collections) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) RestActionListener(org.elasticsearch.rest.action.RestActionListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) 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) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 4 with NodesStatsRequest

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest in project graylog2-server by Graylog2.

the class Cluster method getNodesStats.

public Map<String, NodeStats> getNodesStats(String... nodesIds) {
    final ClusterAdminClient clusterAdminClient = c.admin().cluster();
    final NodesStatsRequest request = clusterAdminClient.prepareNodesStats(nodesIds).request();
    final ImmutableMap.Builder<String, NodeStats> builder = ImmutableMap.builder();
    for (NodeStats nodeStats : clusterAdminClient.nodesStats(request).actionGet().getNodes()) {
        builder.put(nodeStats.getNode().id(), nodeStats);
    }
    return builder.build();
}
Also used : NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with NodesStatsRequest

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest 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)

Aggregations

NodesStatsRequest (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)8 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)5 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)5 NodeClient (org.elasticsearch.client.node.NodeClient)5 Settings (org.elasticsearch.common.settings.Settings)5 RestController (org.elasticsearch.rest.RestController)5 RestRequest (org.elasticsearch.rest.RestRequest)5 GET (org.elasticsearch.rest.RestRequest.Method.GET)5 Table (org.elasticsearch.common.Table)4 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)3 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 Strings (org.elasticsearch.common.Strings)3 RestResponse (org.elasticsearch.rest.RestResponse)3 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2