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.
#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])Save the script as /monitor_es.py and make it executable:
chmod +x /monitor_es.pyStep 1: Write a script to collect cluster status
The Python script above queries the Elasticsearch _cluster/health endpoint and prints the value of a specified field.
Step 2: Configure the Zabbix agent
Edit /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf and add the following user parameter: UserParameter=es.[*],/usr/bin/python /monitor_es.py $1 Restart 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
