安装elasticsearch插件之head

    可以实现对elasticsearch集群的状态监控与管理配置等功能。

    git地址:https://github.com/mobz/elasticsearch-head

二 安装elasticsearch-head

1.1.1 安装

yum install -y npm
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm install grunt -save
ll node_modules/grunt 
npm run start &

1.1.2 浏览器访问测试

1.1.3 elasticsearch开启跨域访问支持

  追加在文件尾部(所有节点都要追加)

[root@Centos-node5 elasticsearch-head]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"

1.1.4 elasticsearch-head连接Elasticsearch测试

1.1.5 模拟查询查看分片

 

 

1.1.6 查看分片信息状态 绿色为正常 

三 脚本监控集群状态

1.1.1 通过shell命令获取集群状态

  获取到的是一个json格式的返回值,那就可以通过python对其中的信息进行分析,例如对status进行分析,如果等于green(绿色)就是运行在正常,等于yellow(黄色)表示副本分片丢失,red(红色)表示主分片丢失

[root@Centos-node5 elasticsearch-head]# curl –sXGET  http://192.168.10.141:9200/_cluster/health?pretty=true
{
  "cluster_name" : "my_elk",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 5,
  "active_shards" : 10,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

1.1.2Python监控

    50为正常100为非正常

[root@Centos-node5 ~]# cat els-cluster-monitor.py 
#!/usr/bin/env python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
import subprocess
body = ""
false="false"
obj = subprocess.Popen(("curl -sXGET http://192.168.10.141:9200/_cluster/health?pretty=true"),shell=True, stdout=subprocess.PIPE)
data =  obj.stdout.read()
data1 = eval(data)
status = data1.get("status")
if status == "green":
    print "50"
else:
    print "100"

[root@Centos-node5 ~]# python els-cluster-monitor.py 
50

 

posted @ 2018-08-03 23:09  闫世成  阅读(249)  评论(0编辑  收藏  举报