How to Monitor Elasticsearch Cluster: Key Commands and Tips
To monitor an
Elasticsearch cluster, use the _cluster/health API to check cluster status and the _nodes/stats API for detailed node metrics. You can also use tools like Kibana or Elastic Stack monitoring features for real-time insights.Syntax
Elasticsearch provides REST APIs to monitor cluster health and node statistics.
GET /_cluster/health: Returns overall cluster health status.GET /_nodes/stats: Provides detailed statistics about each node.GET /_cat/health: Shows a concise health summary in text format.
http
GET /_cluster/health GET /_nodes/stats GET /_cat/health?v
Example
This example shows how to check the cluster health and node stats using curl commands.
bash
curl -X GET "localhost:9200/_cluster/health?pretty" curl -X GET "localhost:9200/_nodes/stats?pretty"
Output
{
"cluster_name" : "my-cluster",
"status" : "green",
"number_of_nodes" : 3,
"active_primary_shards" : 10,
"active_shards" : 20,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
{
"nodes" : {
"node_id_1" : {
"name" : "node-1",
"indices" : {
"docs" : {
"count" : 10000,
"deleted" : 100
},
"store" : {
"size_in_bytes" : 123456789
}
},
"jvm" : {
"mem" : {
"heap_used_in_bytes" : 104857600
}
}
}
}
}
Common Pitfalls
Common mistakes when monitoring Elasticsearch clusters include:
- Not checking cluster health regularly, which can delay detection of issues.
- Ignoring unassigned shards reported by
_cluster/health. - Using only
_catAPIs without detailed stats, missing important metrics. - Not securing API access, exposing sensitive cluster data.
Always combine health checks with node stats and use secured connections.
bash
curl -X GET "localhost:9200/_cluster/health" # Wrong: ignoring unassigned shards # Right: check unassigned shards count and investigate curl -X GET "localhost:9200/_cluster/health?pretty" # Check "unassigned_shards" field for issues
Quick Reference
| API Endpoint | Purpose | Example Usage |
|---|---|---|
| /_cluster/health | Check overall cluster health status | GET /_cluster/health?pretty |
| /_nodes/stats | Get detailed node statistics | GET /_nodes/stats?pretty |
| /_cat/health | Show concise health summary | GET /_cat/health?v |
| /_cat/nodes | List nodes with basic info | GET /_cat/nodes?v |
Key Takeaways
Use the _cluster/health API to monitor overall cluster status regularly.
Check _nodes/stats for detailed node performance and resource usage.
Watch for unassigned shards as a sign of cluster issues.
Secure your monitoring APIs to protect cluster data.
Combine API checks with tools like Kibana for real-time monitoring.