es提供了一个能够获取集群健康状态的api,访问http://esurl:9200/_cluster/health?pretty
和 Elasticsearch 里其余 API 同样,cluster-health 会返回一个 JSON 响应。node
响应的内容解释:python
"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 #可用分片数占总分片的比例 mysql
vim /monitor_es.pysql
#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])
给脚本赋予执行权限chmod +x /monitor_es.py
json
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.confUserParameter=es.[*],/usr/bin/python /monitor_es.py $1
vim
重启zabbix-agentsytemctl restart zabbix-agent
api
建立监控模板
建立应用集
建立监控项
以建立集群健康状态监控项为例
建立完的监控项以下所示
建立触发器
建立图形
将模板连接到监控主机
能够看到添加以后的监控项成功收集到数据 elasticsearch
欢迎各×××陈师傅”ide