参考:http://blog.csdn.net/ptmozhu/article/details/52296958

http://corejava2008.iteye.com/blog/2214279

一.watcher 插件安装
1.在ES_HOME目录下安装License插件:

bin/plugin install license
2.安装watcher插件

bin/plugin install watcher
3.重新启动Elasticsearch

bin/elasticsearch
4.验证是否安装成功

curl -XGET 'http://localhost:9200/_watcher/stats?pretty'

返回结果如下则表示安装成功

{
"watcher_state": "started",
"watch_count": 0,
"execution_thread_pool": {
"queue_size": 0,
"max_size": 0
}
}
二.watcher插件配置使用(报警错误日志)
 Watcher支持的Action类型有四种:EMail(邮件),Webhook(第三方对接),Index(索引),Logging(日志记录)
配置流程:
   1.Schedule the watch and define an input:设置定时器和输入源(错误数据的查询条件)
   2.Add a condition:设置触发条件(condition是否查询到了错误数据)
   3.Take action:设置触发动作(action发现错误后执行)
1.周期搜索日志文件并把结果装载到watcher,使用schedule和input配置。(如下为每隔10秒钟搜索错误日志)
curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '{
  "trigger" : {
    "schedule" : { "interval" : "10s" }
  },
  "input" : {
    "search" : {
      "request" : {
        "indices" : [ "logs" ],
        "body" : {
          "query" : {
            "match" : { "message": "error" }
          }
        }
      }
    }
  }
}'
2.add a condition 设置触发条件(条件为日志错误条数大于0)
curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '{
  "trigger" : { "schedule" : { "interval" : "10s" } },
  "input" : {
    "search" : {
      "request" : {
        "indices" : [ "logs" ],
        "body" : {
          "query" : {
            "match" : { "message": "error" }
          }
        }
      }
    }
  },
  "condition" : {
    "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
  }
}'
3.take action 设置触发动作(以下动作为当错误监测到时把信息写入到Elasticsearch日志中)
curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '{
  "trigger" : { "schedule" : { "interval" : "10s" } },
  "input" : {
    "search" : {
      "request" : {
        "indices" : [ "logs" ],
        "body" : {
          "query" : {
            "match" : { "message": "error" }
          }
        }
      }
    }
  },
  "condition" : {
    "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
  },
  "actions" : {
    "log_error" : {
      "logging" : {
        "text" : "Found {{ctx.payload.hits.total}} errors in the logs"
      }
    }
  }
}'

4.当该报警条件不用时,应当及时删除wacher api(节约计算资源)
curl -XDELETE 'http://localhost:9200/_watcher/watch/log_error_watch'

三.监控ElasticSearch集群状态:每10秒检测一次集群状态,如果集群状态错误(red),则发送邮件给运维
curl -XPUT 'http://localhost:9200/_watcher/watch/cluster_health_watch' -d '{
  "trigger" : {
    "schedule" : { "interval" : "10s" }
  },
  "input" : {
    "http" : {
      "request" : {
       "host" : "localhost",
       "port" : 9200,
       "path" : "/_cluster/health"
      }
    }
  },
  "condition" : {
    "compare" : {
      "ctx.payload.status" : { "eq" : "red" }
    }
  },
  "actions" : {
    "send_email" : {
      "email" : {
        "to" : "<username>@<domainname>",
        "subject" : "Cluster Status Warning",
        "body" : "Cluster status is RED"
      }
    }
  }
}'

如果配置邮件发送,需要在ElasticSearch配置文件elasticsearch.yaml中配置以下信息
watcher.actions.email.service.account:  
  work:  
    profile: gmail  
    email_defaults:  
      from: <email>   
    smtp:  
      auth: true  
      starttls.enable: true  
      host: smtp.gmail.com  
      port: 587  
      user: <username>   
      password: <password>   
邮件报警(profile)默认支持standard (default), gmail, and outlook。下面我使用163邮箱profile改为standard.
端口号使用25,同时必须在163邮箱中配置允许第三方邮箱客户端登陆,使用授权码登陆,而不是邮箱密码
watcher.actions.email.service.account:
  work:
    profile: standard
    email_defaults:
      from: '<yourname>@163.com'
    smtp:
      auth: true
      starttls.enable: true
      host: smtp.163.com
      port: 25
      user: yourname@163.com
      password: password

Elasticsearch报警插件Watch安装以及使用的更多相关文章

  1. elasticsearch分词插件的安装

    IK简介 IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包.从2006年12月推出1.0版开始, IKAnalyzer已经推出了4个大版本.最初,它是以开源项目Luen ...

  2. 报警插件Alertmanager 安装与使用

    Alertmanager是一个独立的告警模块,接收Prometheus等客户端发来的警报,之后通过分组.删除重复等处理,并将它们通过路由发送给正确的接收器:告警方式可以按照不同的规则发送给不同的模块负 ...

  3. 转:ElasticSearch的安装和相关插件的安装

    原文来自于:http://blog.csdn.net/whxaing2011/article/details/18237733 本文主要介绍如下内容:          1.ElasticSearch ...

  4. ElasticSearch head 插件安装

    head 客户端可以很方便在上面创建索引,类型,文档,还有查询,使用它管理elasticsearch 提高效率. 在安装head 客户端之前必须安装node.js 环境,因为它是用node.js 编写 ...

  5. ubuntu安装elasticSearch及插件

    原文地址:http://www.niu12.com/article/18 前提 1.安装好Java1.8以上环境并配置好JAVA_HOME(elasticsearch运行环境) 2.node环境6.5 ...

  6. Elasticsearch之Hadoop插件的安装(图文详解)

    这个Hadoop插件的安装是非常重要. Hadoop插件安装 在es的安装目录下 bin/plugin install elasticsearch/elasticsearch-repository-h ...

  7. ElasticSearch 5.2.2 安装及 head 插件的安装

    ElasticSearch 是一个基于 Lucene 的高度可扩展的开源全文搜索和分析引擎.它能够做到可以快速.实时地存储.搜索和分析大量数据.它通常作为底层引擎/技术,为具有复杂搜索功能和要求的应用 ...

  8. Linux下,非Docker启动Elasticsearch 6.3.0,安装ik分词器插件,以及使用Kibana测试Elasticsearch,

    Linux下,非Docker启动Elasticsearch 6.3.0 查看java版本,需要1.8版本 java -version yum -y install java 创建用户,因为elasti ...

  9. ELK 学习笔记之 elasticsearch head插件安装

    elasticsearch head插件安装: 准备工作: 安装nodejs和npm https://nodejs.org/en/download/ node-v6.11.2-linux-x64.ta ...

随机推荐

  1. Laravel应用性能调优

    这次性能测试方案中用到的优化技巧主要基于 Laravel 框架本身及其提供的工具. 关闭应用debugapp.debug=false 缓存配置信息php artisan config:cache 缓存 ...

  2. Dictionary 的几种遍历方法

    Dictionary 的几种遍历方法 Dictionary<string, int>dic = newDictionary<string, int>(); 方法1 foreac ...

  3. RAMPS1.4 3d打印控制板接线与测试4

    如果之前的操作都顺利,现在就可以插上USB线,打开printrun上位机软件了.mega2560刚刚接通电源时,RAMPS板子上的LED1(绿色)会闪几下.这说明mega2560板子中的固件正在启动. ...

  4. Setting a maximum attachment size

      By default IBM® Lotus® iNotes™ allows a maximum attachment size of 50,000K (50MB). You can increas ...

  5. ERROR: In &lt;declare-styleable&gt; MenuView, unable to find attribute android:preserveIconSpacing

    eclipse  sdk从低版本号切换到高版本号sdk的时候   v7包会包这个错ERROR: In <declare-styleable> MenuView, unable to fin ...

  6. linux设置开机同步时间

    在/etc/init.d/下新建zhjdate脚本,添加如下内容: #!/bin/bash# chkconfig: 345 63 37#chkconfig:345 63 37 (数字345是指在运行级 ...

  7. Android 演示 DownloadManager——Android 下载 apk 包并安装

    本文内容 环境 项目结构 演示下载 参考资料 本文是 github 上 Trinea-Android-common 和 Trinea-Android-Demo 项目的一部分,将下载部分分离出来,看看如 ...

  8. 分布式锁与实现(一)——基于Redis实现(转载)

    php的完整流程,包护队列操作:http://www.cnblogs.com/candychen/p/5736128.html 概述 目前几乎很多大型网站及应用都是分布式部署的,分布式场景中的数据一致 ...

  9. LintCode: Single Number II

    一篇解析比较详细的文章:http://www.acmerblog.com/leetcode-single-number-ii-5394.html C++ 解法(1) 求出每个比特位的数目,然后%3,如 ...

  10. ZH奶酪:Ubuntu 14.04配置LAMP(Linux、Apache、MySQL、PHP)

    ZH奶酪:Ubuntu 14.04安装LAMP(Linux,Apache,MySQL,PHP) 之前已经介绍过LAMP的安装,这边文章主要讲解一下LAMP的配置. 1.配置Apache (1)调整Ke ...