Zabbix監控elasticsearch集羣健康狀態(附模板)

es提供了一個能夠獲取集羣健康狀態的api,訪問http://esurl:9200/_cluster/health?pretty
和 Elasticsearch 裏其餘 API 同樣,cluster-health 會返回一個 JSON 響應。
Zabbix監控elasticsearch集羣健康狀態(附模板)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

1.編寫採集腳本獲取集羣狀態

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

2.修改zabbix-agent配置文件

vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
UserParameter=es.[*],/usr/bin/python /monitor_es.py $1vim

重啓zabbix-agent
sytemctl restart zabbix-agentapi

3.配置監控模板

建立監控模板
Zabbix監控elasticsearch集羣健康狀態(附模板)
建立應用集
Zabbix監控elasticsearch集羣健康狀態(附模板)
建立監控項
以建立集羣健康狀態監控項爲例
Zabbix監控elasticsearch集羣健康狀態(附模板)
建立完的監控項以下所示
Zabbix監控elasticsearch集羣健康狀態(附模板)
建立觸發器
Zabbix監控elasticsearch集羣健康狀態(附模板)
Zabbix監控elasticsearch集羣健康狀態(附模板)
建立圖形
Zabbix監控elasticsearch集羣健康狀態(附模板)
將模板連接到監控主機
Zabbix監控elasticsearch集羣健康狀態(附模板)
能夠看到添加以後的監控項成功收集到數據
Zabbix監控elasticsearch集羣健康狀態(附模板) elasticsearch


歡迎各×××陳師傅」
Zabbix監控elasticsearch集羣健康狀態(附模板)ide

相關文章
相關標籤/搜索