英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论