Operations 4 min read

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.

Ops Development Stories
Ops Development Stories
Ops Development Stories
How to Monitor Elasticsearch Cluster Health with Zabbix: Step‑by‑Step Guide

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.py

and make it executable:

chmod +x /monitor_es.py

Step 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-agent

Step 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.

PythonoperationsElasticsearchZabbixCluster Monitoring
Ops Development Stories
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.