Search code examples
elasticsearchelastic-stackelasticsearch-7

How to know total nodes in an elasticsearch cluster?


I have 3 nodes elasticsearch cluster. If more than one node goes down then I can easily check them manually. Suppose nodes in the cluster got increased then it will be difficult to check them manually. So, how can I get all the nodes(specifically name of the nodes) of the cluster even if they are down?

To get live/healthy nodes I hit the api endpoint:

curl -X GET "hostname/ip:port/_cat/nodes?v&pretty"

Is there any endpoint by using which I can get total nodes and unhealthy/down nodes in elasticsearch cluster?

I was trying to list all the nodes using discovery.seed.hosts present in elasticsearch.yml config file. But I don't know how to do it or is it the right approach or not.


Solution

  • I don't think there is any API to know about offline nodes. If your entire cluster is down or single node down, then Elastic doesn't provide any way to check the node's health. You need to depend on an external script or code or monitoring tool which will ping all your nodes and print status.

    You can write a custom script which will call below API and it will return all the nodes which are available in the cluster. Once you have received response, you can filter out IP or hostname of the node and whichever are not coming in response you can consider it as down node.

    GET _cat/nodes?format=json&filter_path=ip,name
    

    Another option is to enable cluster monitoring which will give you status of entire cluster but again it will show information about running node only.

    Please check this answer for how Kibana show offline node in Cluster Monitoring.