监控 Elasticsearch 集群状态1 min read

  • 4
  • 5,157 views
  • A+
所属分类:ELKstack

  

监控主要命令(只需要将命令里面的地址换成自己的即可):

  1. [root@elk-node1 ~]# curl -sXGET http://192.168.56.31:9200/_cluster/health?pretty=true  
  2. {  
  3.   "cluster_name" : "elk-cluster",  
  4.   "status" : "green",  
  5.   "timed_out" : false,  
  6.   "number_of_nodes" : 2,  
  7.   "number_of_data_nodes" : 2,  
  8.   "active_primary_shards" : 0,  
  9.   "active_shards" : 0,  
  10.   "relocating_shards" : 0,  
  11.   "initializing_shards" : 0,  
  12.   "unassigned_shards" : 0,  
  13.   "delayed_unassigned_shards" : 0,  
  14.   "number_of_pending_tasks" : 0,  
  15.   "number_of_in_flight_fetch" : 0,  
  16.   "task_max_waiting_in_queue_millis" : 0,  
  17.   "active_shards_percent_as_number" : 100.0  
  18. }  

  

编写python监控脚本如下:

  1. #!/usr/bin/python env  
  2. # coding: utf-8  
  3.   
  4. import subprocess  
  5. body = " "  
  6. false="false"  
  7. obj = subprocess.Popen(("curl -sXGET http://192.168.56.31:9200/_cluster/health?pretty=true"),shell=True, stdout=subprocess.PIPE)  
  8. data = obj.stdout.read()  
  9. data1 = eval(data)  
  10. status = data1.get("status")  
  11. if status == "green":  
  12.     print "50"  
  13. else:  
  14.     print "100"  

说明:集群状态如果是 green 就让它打出50,否则打出100,这样就可以结合 zabbix 进行监控报警了

   

zhaoyulin

发表评论取消回复

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:4   其中:访客  0   博主  0

    • 匿名 匿名 1

      不想评论~~~

        • zhaoyulin zhaoyulin Admin

          @匿名 哈哈哈

        • 匿名 匿名 1

          不想评论➕1

          • 祖国的小花 祖国的小花 2

            飘过~