简单命令监控elasticsearch集群状态

原理:
使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green
curl -sXGET http://serverip:9200/_cluster/health/?pretty

{
  "cluster_name" : "yunva-es",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 7,
  "number_of_data_nodes" : 6,
  "active_primary_shards" : 66,
  "active_shards" : 132,
  "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
}

前端使用了nginx验证,需要模拟登陆
curl模拟用户登录命令格式:
curl -u username:password -sXGET http://serverip:9200/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'

1.修改客户端zabbix配置:
vim /etc/zabbix/zabbix_agentd.conf

UserParameter=es_status,curl -u elkadmin:hSeC7ENeirAAPzv047m4 -sXGET http://serverip/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'|grep -c 'green'

重启zabbix-agent使配置生效
service zabbix-agent restart

在zabbix-server端测试
zabbix_get -s ip -p 10050 -k es_status

2.在zabbix的web页面添加对应的监控:

添加监控项item

Confuguration --> Hosts --> 找到对应的主机,点开 Items --> Create item


创建触发器:
Name
es_status_check
es_cluster_status is not green

3.针对es集群中的每个节点做进程监控,如果进程挂了自动重启

配置监控进程item

配置触发器

配置action,看参考

zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务

http://blog.csdn.net/reblue520/article/details/52315154

触发脚本:

/usr/local/zabbix-agent/scripts/start_es.sh

#!/bin/bash
# if elasticsearch exists kill it
source /etc/profile
count_es=`ps -ef|grep elasticsearch|grep -v grep|wc -l`
if [ $count_es -gt 1 ];then
ps -ef|grep elasticsearch|grep -v grep|/bin/kill `awk '{print $2}'`
fi
# start it su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &"

执行:
sudo /bin/bash /usr/local/zabbix-agent/scripts/start_es.sh
报错:
which: no java in (/sbin:/bin:/usr/sbin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

解决办法:
在脚本中添加
source /etc/profile

以root用户运行elasticsearch

报错:
can not run elasticsearch as root

网上的方法,针对elasticsearch5.1不起作用
解决方法1:
在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下

./elasticsearch -Des.insecure.allow.root=true  
解决办法2:
用vi打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令

ES_JAVA_OPTS="-Des.insecure.allow.root=true"

解决办法:
su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &"

自动拉起kibana服务的脚本:
cat /usr/local/zabbix/scripts/restart_kibana.sh
#!/bin/bash
# if kibana exists kill it

count_kibana=`ps -ef|grep kibana|grep -v grep|wc -l`
if [ $count_kibana -eq 1 ];then
    ps -ef|grep kibana|grep -v grep|/bin/kill `awk '{print $2}'`
fi
# start it

# 小小总结一下

.修改zabbix_agentd.conf文件打开远程shell命令
# egrep -v '^#|^$' /usr/local/zabbix_agents_3.2.0/scripts/conf/zabbix_agentd.conf EnableRemoteCommands=
UnsafeUserParameters= # 打开zabbix的命令 echo "Defaults:zabbix !requiretty" >> /etc/sudoers
zabbix ALL=(ALL) NOPASSWD: ALL >> /etc/sudoers .监控命令 UserParameter=es_status,curl -sXGET http://172.16.0.230:9200/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'|grep -c 'green'
UserParameter=es_debug,sudo /bin/find /opt/elasticsearch-5.6. -name hs_err_pid*.log -o -name java_pid*.hprof|wc -l
# 默认的端口监控可能出问题,替换为如下命令
UserParameter=net.tcp.listen.grep[*],grep -q $(printf '%04X.00000000:0000.0A' $) /proc/net/tcp ;if [ $? -eq ];then echo ;else grep -q "$(printf '%04X 0000000000000000000000 0000000000:0000 0A' $1)" /proc/net/tcp6;if [ $? -eq ];then echo ;else echo ;fi;fi .当出现java内存溢出时触发重启elasticsearch的脚本 # vim /usr/local/zabbix_agents_3.2.0/scripts/start_es.sh #!/bin/bash
# if elasticsearch exists kill it
source /etc/profile # 删除java报错产生的文件
/usr/bin/sudo /bin/find /opt/elasticsearch-5.6. -name hs_err_pid*.log -o -name java_pid*.hprof | xargs rm -f # kill并重新启动elasticsearch
count_es=`ps -ef|grep elasticsearch|grep -v grep|wc -l`
if [ $count_es -ge ];then
ps -ef|grep elasticsearch|grep -v grep|/bin/kill - `awk '{print $2}'`
fi
# start it
su elasticsearch -c "cd /opt/elasticsearch-5.6.15/bin && /bin/bash elasticsearch -d" .监控模板 <?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.2</version>
<date>--09T06::18Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>es_cluster_monitor</template>
<name>es_cluster_monitor</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications/>
<items>
<item>
<name>es_debug</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>es_debug</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>es_status</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>es_status</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>es_9200</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>net.tcp.listen.grep[]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>es_9300</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>net.tcp.listen.grep[]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>es_process</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>proc.num[,,all,elasticsearch]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item>
</items>
<discovery_rules/>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{cms_uts_es:es_status.last()}&lt;&gt; and {cms_uts_es:es_status.last()}&lt;&gt; and {cms_uts_es:es_status.last()}&lt;&gt;</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>es cluster is not green</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>{cms_uts_es:proc.num[,,all,elasticsearch].last()}&lt; and {cms_uts_es:proc.num[,,all,elasticsearch].last()}&lt; and {cms_uts_es:proc.num[,,all,elasticsearch].last()}&lt;</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>es process was down</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>{cms_uts_es:net.tcp.listen.grep[].max(#)}=</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>es_9200 port down</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>{cms_uts_es:net.tcp.listen.grep[].max(#)}=</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>es_9300 port down</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>{cms_uts_es:es_debug.last()}&lt;&gt;</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>es_debug error</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger>
</triggers>
</zabbix_export>

zabbix通过简单命令监控elasticsearch集群状态的更多相关文章

  1. zabbix通过简单shell命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...

  2. 如何监控 Elasticsearch 集群状态?

    Marvel 让你可以很简单的通过 Kibana 监控 Elasticsearch.你可以实时查看你 的集群健康状态和性能,也可以分析过去的集群.索引和节点指标.

  3. 和我一起打造个简单搜索之ElasticSearch集群搭建

    我们所常见的电商搜索如京东,搜索页面都会提供各种各样的筛选条件,比如品牌.尺寸.适用季节.价格区间等,同时提供排序,比如价格排序,信誉排序,销量排序等,方便了用户去找到自己心里理想的商品. 站内搜索对 ...

  4. zabbix监控Elasticsearch集群

    本节以 zabbix 为例,介绍如何使用监控系统完成 Elasticsearch 的监控报警. github 上有好几个版本的 ESZabbix 仓库,都源自 Elastic 公司员工 unterge ...

  5. Prometheus监控elasticsearch集群(以elasticsearch-6.4.2版本为例)

    部署elasticsearch集群,配置文件可"浓缩"为以下: cluster.name: es_cluster node.name: node1 path.data: /app/ ...

  6. ElasticSearch集群状态查看命令大全

    Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...

  7. ElasticSearch集群状态查看命令大全(转)

    原文地址: https://blog.csdn.net/pilihaotian/article/details/52460747 Elasticsearch中信息很多,同时ES也有很多信息查看命令,可 ...

  8. Elasticsearch集群状态脚本及grafana监控面板导出的json文件

    脚本文件: #!/usr/bin/env python import datetime import time import urllib import json import urllib2 imp ...

  9. Elasticsearch集群状态查看命令

    _cat $ curl localhost:9200/_cat=^.^=/_cat/allocation/_cat/shards/_cat/shards/{index}/_cat/master/_ca ...

随机推荐

  1. Web应用:当文件超过100KB,无法上传,有种原因你想象不到

    今天下午2点多,突然发现凡是文件超过100KB的,在上传的时候都会卡住,但低于100KB的文件可以上传成功. 服务器端使用的是asp无组件上传,为什么突然出现这种问题呢? 我们知道,IIS默认上传限制 ...

  2. Python基础学习(五)

    一.使用模块 已经了解了什么是模块,模块就是一个个文件的体,我们可以做不同的文件中引入各个模块文件,当然如果模块有冲突,还可以给模块文件的上层建立一个目录简称包,包名只能唯一,不能重名. 另外,一旦建 ...

  3. FTP文件乱码和传输模式解释

    转: FTP文件乱码和传输模式解释 2017年02月18日 10:50:03 -Hermes- 阅读数:12112更多 所属专栏: 异常解决方案急诊室   版权声明:大侠,在转载时请注明出处,小弟不胜 ...

  4. (JAVA保留小数问题,基础)Probability hdu2131

    Probability 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2131 Time Limit: 3000/1000 MS (Java/Others) ...

  5. JS中的数据类型和变量内存

    1. JS中存在5种简单数据类型和1种复杂数据类型: 5种简单数据类型:Undefined, Null, Boolean, Number, String. 1种复杂数据类型:Object. 上面的5种 ...

  6. models.DateTimeField(auto_now_add=True) 与 models.DateTimeField(auto_now=True)

    DateTimeField和DateField和TimeField存储的内容分别对应着datetime(),date(),time()三个对象. 对于auto_now=False和auto_now_a ...

  7. ACPI:Memory错误解决办法

    Linux系统装在vmware12中,打开虚拟机时报错,报错内容大概如下: ACPI:memory_hp:Memory online failed for 0x100000000 - 0x400000 ...

  8. Makefile 中符合的使用

    1. $@: 表示规则中的目标文件集.在模式规则中,如果有多个目标,那么,"$@"就是匹配于 目标中模式定义的集合 2. $^  : 所有的依赖目标的集合.以空格分隔.如果在依赖目 ...

  9. javascript 体验倒计时:距离国庆还有多长时间

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Jmeter调用 Json接口测试之关键点申明Content-Type类型

    背景: 最近,在做接口测试发现创建运单接口,通过普通表单请求总是失败,开始我以为是后端接口出现问题,但通过前端页面都能创建运单,F12打开浏览器开发者模式,获取该接口请求入参发现,请求的数据格式是js ...