zabbix監控ES集羣健康狀態

  當收集的數據出如今圖形以後,我慢慢感受,整個ES的監控都沒什麼意義。其實,只要能保證ES的正常狀態,大部分參數(特別是圖形上的大多數監控值),對於小企業來講,並無什麼現實意義。既然搞出來了,那就索性整理好筆記吧。筆記完成後,我準備把大部分ES的監控所有禁用!node


1. 獲取集羣健康狀態的apiweb

  ES提供了一個能夠獲取集羣健康狀態的api,在瀏覽器訪問:http://10.253.40.87:9200/_cluster/health?pretty
shell

  和Elasticsearch裏其餘API同樣,「cluster-health」會返回一個JSON響應。api

blob.png

  響應的內容解釋:瀏覽器

"cluster_name" : "my-application",     #集羣名bash

"status" : "green",             #集羣健康狀態,正常的話是「green」,缺乏副本分片爲「yellow」,缺乏主分片爲「red」app

"timed_out" : false,curl

"number_of_nodes" : 2,           #集羣節點數elasticsearch

"number_of_data_nodes" : 2,        #數據節點數ide

 "active_primary_shards" : 138,      #主分片數

 "active_shards" : 274,          #可用的分片數

"relocating_shards" : 0,          #正在遷移的分片數

 "initializing_shards" : 0,        #正在初始化的分片數

"unassigned_shards" : 0,          #未分配的分片,但在集羣中存在

"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" : 100.0  #可用分片數佔總分片的比例


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

[root@iZejm6lkdZ ~]# cat /etc/zabbix/scripts/monitor_es.sh
#!/bin/bash
case $1 in
    cluster_name)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\" '/cluster_name/ {print $4}' ;;
    status)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\" 'NR==3 {print $4}' ;;
    timed_out)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==4 {print $1}' |awk -F: '{print $2}' ;;
    number_nodes)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==5 {print $1}' |awk -F: '{print $2}' ;;
    data_nodes)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==6 {print $1}' |awk -F: '{print $2}' ;;
    active_primary_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==7 {print $1}' |awk -F: '{print $2}' ;;
    active_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==8 {print $1}' |awk -F: '{print $2}' ;;
    relocating_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==9 {print $1}' |awk -F: '{print $2}' ;;
    initializing_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==10 {print $1}' |awk -F: '{print $2}' ;;
    unassigned_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==11 {print $1}' |awk -F: '{print $2}' ;;
    delayed_unassigned_shards)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==12 {print $1}' |awk -F: '{print $2}' ;;
    number_of_pending_tasks)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==13 {print $1}' |awk -F: '{print $2}' ;;
 
 
    active_shards_percent_as_number)
        curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==16 {print $1}' |awk -F: '{print $2}' ;;
    *)
 
        echo "Usage: $0 { cluster_name | status | timed_out | number_nodes | data_nodes | active_primary_shards | active_shards | relocating_shards | initializing_shards | unassigned_shards|delayed_unassigned_shards|number_of_pending_tasks|active_shards_percent_as_number}" ;;
esac

  在shell腳本里,「curl -s -XGET 'http://10.253.40.87:9200/_cluster/health?pretty' |awk -F\, 'NR==16 {print $1}' |awk -F: '{print $2}'」這樣的命令,「NR==16」是指在瀏覽器訪問http://10.253.40.87:9200/_cluster/health?pretty,獲取頁面的第16行(從第1行的「{」開始計數)。

  給腳本授予執行權限:

chmod +x monitor_es.sh

  屬主、屬組可能也須要受權:

chown zabbix:zabbix monitor_es.sh

3. 增長zabbix-agent配置文件

[root@iZejm6lkdZ ~]# cat /etc/zabbix/zabbix_agentd.d/monitor_es.conf
UserParameter=es_cluster_name,/etc/zabbix/scripts/monitor_es.sh cluster_name
UserParameter=es_status,/etc/zabbix/scripts/monitor_es.sh status
#UserParameter=timed_out,/etc/zabbix/scripts/monitor_es.sh timed_out
 
UserParameter=es_number_nodes,/etc/zabbix/scripts/monitor_es.sh number_nodes
UserParameter=es_data_nodes,/etc/zabbix/scripts/monitor_es.sh data_nodes
UserParameter=es_active_primary_shards,/etc/zabbix/scripts/monitor_es.sh active_primary_shards
UserParameter=es_active_shards,/etc/zabbix/scripts/monitor_es.sh active_shards
UserParameter=es_relocating_shards,/etc/zabbix/scripts/monitor_es.sh relocating_shards
UserParameter=es_initializing_shards,/etc/zabbix/scripts/monitor_es.sh initializing_shards
UserParameter=es_unassigned_shards,/etc/zabbix/scripts/monitor_es.sh unassigned_shards
UserParameter=es_delayed_unassigned_shards,/etc/zabbix/scripts/monitor_es.sh delayed_unassigned_shards
UserParameter=es_number_of_pending_tasks,/etc/zabbix/scripts/monitor_es.sh number_of_pending_tasks
UserParameter=es_active_shards_percent_as_number,/etc/zabbix/scripts/monitor_es.sh active_shards_percent_as_number

  有行腳本被註釋,只是沒有加入監控,沒有其餘意思。目前不肯定這個監控項的含義,之後能夠再添加。

4. 重啓zabbix-agent服務(zabbix-agent其實有多種重啓方式,好像有3種方法,這應該和安裝方法有關。這裏是咱們生產環境惟一輩子效的方法)

[root@iZejm6lkdZ ~]# pkill -f /etc/zabbix/zabbix_agentd.conf
[root@iZejm6lkdZ ~]# ps -ef|grep zabbix_agent
root     26152  8156  0 16:06 pts/3    00:00:00 grep --color=auto zabbix_agent
[root@iZejm6lkdZ ~]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
[root@iZejm6lkdZ ~]# ps -ef|grep zabbix_agent
root     26155     1  0 16:06 ?        00:00:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
root     26156 26155  0 16:06 ?        00:00:00 zabbix_agentd: collector [idle 1 sec]
root     26157 26155  0 16:06 ?        00:00:00 zabbix_agentd: listener #1 [waiting for connection]
root     26158 26155  0 16:06 ?        00:00:00 zabbix_agentd: listener #2 [waiting for connection]
root     26159 26155  0 16:06 ?        00:00:00 zabbix_agentd: listener #3 [waiting for connection]
root     26160 26155  0 16:06 ?        00:00:00 zabbix_agentd: active checks #1 [idle 1 sec]
root     26162  8156  0 16:06 pts/3    00:00:00 grep --color=auto zabbix_agent

5. web頁面配置

  item添加:

blob.png

  因爲收集的信息只有「green」、「yellow」和「red」,因此,這裏的信息類型爲字符型。

  只有「es集羣名稱」和「es集羣狀態」2個監控項的「Type of information」(字段類型)是字符型的,其餘監控項必須是數值型的。例如:

blob.png

  因爲「es集羣名稱」和「es集羣狀態」的字段類型是字符型的,因此「Trends」列這個監控項是空的。

  這一點很重要。

  若是全部監控項都是字符型,那麼,在後面添加「圖形」時,監控項是找不到的。

blob.png

  放大圖:

blob.png

  觸發器的建立:

blob.png

  點擊「Add」按紐,須要填寫的信息:

blob.png

  注意:「Function」和「N」是重點。

  這個觸發器表達式的意思是,當字符串長度爲3,也就是狀態值爲「red」,觸發報警。

  圖形建立:

blob.png

  點擊下面的「Add」按紐,在彈出的對話框裏能看到此次建立的監控項,就是由於這些監控項的字段類型是數值型。當前,字符型的2個監控項這裏就不存在。

blob.png

  當前zabbix收集數據沒有問題:

blob.png


  參考文檔:

https://blog.51cto.com/766792592/1891112——zabbix監控elasticsearch集羣

https://mp.weixin.qq.com/s?__biz=MzIyMDY2MTE3Mw==&mid=2247484711&idx=1&sn=c011a564d2eec95e64ef01cc6410314e&chksm=97c9d1fda0be58ebd945bcf2805900a4d61f4cf57722bf3a7682f285fdf00c95491462d0808d&mpshare=1&scene=23&srcid=#rd——Zabbix監控es集羣狀態

相關文章
相關標籤/搜索