通过http://127.0.0.1:9200/_cluster/health地址返回的数据
“cluster_name”: “my-es”, #集群名
“status”: “yellow”, #集群健康状态,正常的话是green,缺少副本分片为yellow,缺少主分片为red
“timed_out”: false,
“number_of_nodes”: 1,#集群节点数
“number_of_data_nodes”: 1,#数据节点数
“active_primary_shards”: 15,#主分片数
“active_shards”: 15,#可用的分片数
“relocating_shards”: 0,#正在迁移的分片数
“initializing_shards”: 0,#正在初始化的分片数
“unassigned_shards”: 15, #未分配的分片,但在集群中存在
“delayed_unassigned_shards”: 0, #延时待分配到具体节点上的分片数
“number_of_pending_tasks”: 0, #待处理的任务数,指主节点创建索引并分配shards等任务
“number_of_in_flight_fetch”: 0, #未完成的提取次数
“task_max_waiting_in_queue_millis”: 0, #任务最大等待时长(以毫秒为单位)
“active_shards_percent_as_number”: 50 #可用分片数占总分片的比例
通过python脚本对数据进行解析,然后通过添加zabbix模版来监控es集群状态
python脚本:monitor.py
#!/usr/bin/python
#encoding=utf-8
import requests
import 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://127.0.0.1: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])
配置zabbix_agent
[root@centos zabbix_agentd.conf.d]# pwd
/data/zabbix_agent/etc/zabbix_agentd.conf.d
[root@centos zabbix_agentd.conf.d]# ls
checkping.conf getindex.conf monitor.conf
[root@centos zabbix_agentd.conf.d]# cat monitor.conf
UserParameter=es[*],/data/script/monitor.py $1
[root@centos zabbix_agentd.conf.d]#
配置完需要重启zabbix_agent,在zabbix server上测试是否能获取数据
[root@zabbix ~]# zabbix_get -s 172.10.10.121 -k "es[status]"
green
[root@zabbix ~]#
可以正常获取到数据,接下来配置zabbix模版
键值这里填写的是:es[number_of_nodes],number_of_nodes是文章开头介绍的es的返回的数据key,其他的监控项目类似,添加完成后的效果
接下来创建图形
告警触发器可以根据需要自定义添加