How to Monitor Elasticsearch Cluster Health with Zabbix: Step‑by‑Step Guide
This guide explains how to retrieve Elasticsearch cluster health via its API, write a Python script to extract specific metrics, integrate it with Zabbix by configuring user parameters, and create monitoring templates, items, triggers, and graphs to visualize cluster status.
Elasticsearch provides an API to obtain cluster health, for example
http://esurl:9200/_cluster/health?pretty, which returns a JSON response containing fields such as cluster_name , status , number_of_nodes , and others.
<code>#encoding=utf-8
import requests,json
import sys
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"}
response=requests.get("http://192.168.179.133:9200/_cluster/health",headers=headers)
s=json.loads(response.content.decode())
parm=sys.argv[1]
itemlist=["cluster_name","status","timed_out","number_of_nodes","number_of_data_nodes","active_primary_shards","active_shards","relocating_shards","initializing_shards","unassigned_shards","delayed_unassigned_shards","number_of_pending_tasks","number_of_in_flight_fetch","task_max_waiting_in_queue_millis","active_shards_percent_as_number"]
if parm not in itemlist:
print("parm failed")
sys.exit(1)
else:
print(s[parm])
</code>Save the script as
/monitor_es.pyand make it executable:
chmod +x /monitor_es.pyStep 1: Write a script to collect cluster status
The Python script above queries the Elasticsearch
_cluster/healthendpoint and prints the value of a specified field.
Step 2: Configure the Zabbix agent
Edit
/etc/zabbix/zabbix_agentd.d/userparameter_mysql.confand add the following user parameter:
UserParameter=es.[*],/usr/bin/python /monitor_es.py $1Restart the Zabbix agent to apply the changes:
systemctl restart zabbix-agentStep 3: Create a monitoring template in Zabbix
Create a new template, link it to the target host, and add items, triggers, and graphs for the Elasticsearch health metrics. The screenshots below illustrate each step.
After linking the template to the host, the newly created items start collecting data, as shown in the final screenshot.
This completes the setup for monitoring Elasticsearch cluster health with Zabbix.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.