Home > Back-end >  How to know total nodes in an elasticsearch cluster?
How to know total nodes in an elasticsearch cluster?

Time:03-31

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.

CodePudding user response:

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 don't provide any way to check nodes health. You need to depend on external script or code or monitor tool which will ping your all node 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.

  • Related