Skip to content
Advertisement

Find total amount of disk space used by a Elasticsearch cluster

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?

Advertisement

Answer

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
},
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement