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