查找Elasticsearch集群使用的总磁盘空间量

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

Find total amount of disk space used by a Elasticsearch cluster

问题

我正在寻找一种获取Elasticsearch集群使用的总磁盘空间的方法。我已经找到建议使用以下REST API端点之一来获取此信息以及其他信息:

GET /_cat/stats
GET /_nodes/stats

我想知道是否可以使用Elasticsearch Java高级REST客户端或较早版本Elasticsearch中的传输客户端获得相同的信息?

英文:

I am looking for a way to get the total amount of disk space used by a
Elasticsearch cluster. I have found suggestions to use the following REST API endpoints to obtain this information among other things:

GET /_cat/stats
GET /_nodes/stats

I was wondering can the same information be obtained using the Elasticsearch Java High-Level REST Client or the Transport Client in an older version of Elasticsearch?

答案1

得分: 2

是的,您说得对,可以使用 _nodes/stats API 获取磁盘统计信息,因为 REST 高级客户端没有提供节点统计的直接 API。您可以在这里查看它支持的所有 API。

但是您可以使用高级客户端中提供的低级 REST 客户端,下面是工作示例代码:

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

您可以看到,我在控制台上打印了上述 API 的输出,并验证了它包含磁盘使用情况的状态,其格式如下:

"most_usage_estimate": {
    "path": "/home/opster/runtime/elastic/elasticsearch-7.8.1/data/nodes/0",
    "total_in_bytes": 124959473664,
    "available_in_bytes": 6933352448,
    "used_disk_percent": 94.45151916481107
},
英文:

Yes, you are correct that disk stats can be obtained using the _nodes/stats API as REST high-level client doesn't provide any direct API for node stats, you can see all the API supported by it here.

But you can use the low level rest client which is provide in high level client and below is the working example code.

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

You can see I am printing the O/P of above API on console and verified that it contains the disk usage status which comes in below format:

"most_usage_estimate": {
"path": "/home/opster/runtime/elastic/elasticsearch-7.8.1/data/nodes/0",
"total_in_bytes": 124959473664,
"available_in_bytes": 6933352448,
"used_disk_percent": 94.45151916481107
},

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

发表评论

匿名网友

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

确定