使用Java Rest High Level Client获取Elasticsearch节点的IP地址和其他详细信息。

huangapple go评论99阅读模式
英文:

Elasticsearch Node IP address and other details using java rest high level client

问题

如何使用Java高级REST客户端获取Elasticsearch的节点详细信息。
我们可以在Kibana中使用GET /_cat/nodes获取节点详细信息。
我想知道如何使用高级REST客户端获取相同的详细信息,我需要节点的IP地址以及它是否为主节点。

英文:

How can we get node details for elasticseacrh using java high level rest client.
We can get node details in KIbana using GET /_cat/nodes .
I want to how to get same details using high level rest client , i need IP address of nodes and wether its master node or not.

答案1

得分: 1

看起来 JHLRC 没有用于获取 _cat/nodes API 的接口,但可以通过在 JHLRC 中使用低级客户端轻松获取,如下所示的代码:

private void getNodesAPI(RestHighLevelClient restHighLevelClient) throws IOException {
    RestClient lowLevelClient = restHighLevelClient.getLowLevelClient();
    Request request = new Request(
        "GET",
        "/_cat/nodes?v");
    Response response = lowLevelClient.performRequest(request);
    if (response.getStatusLine().getStatusCode() == 200) {
        System.out.println("resp: \n" + EntityUtils.toString(response.getEntity()));
    }
}

在本地运行了上述代码,结果如下所示输出到控制台:

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           48          99  21    2.59    1.93     1.92 *    opster
英文:

Looks like JHLRC doesn't have a API to get _cat/nodes API, but it can be easily obtained using the low-level client which is available within JHLRC as shown in below code

private void getNodesAPI(RestHighLevelClient restHighLevelClient) throws IOException {
        RestClient lowLevelClient = restHighLevelClient.getLowLevelClient();
        Request request = new Request(
                "GET",
                "/_cat/nodes?v");
        Response response = lowLevelClient.performRequest(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("resp: \n"+ EntityUtils.toString(response.getEntity()));
        }
    }

Ran above code locally and it works and below is the O/P on console

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           48          99  21    2.59    1.93     1.92 *    opster

huangapple
  • 本文由 发表于 2020年9月16日 23:07:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63922961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定