Elasticsearch报警插件Watch安装以及使用
参考: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安装以及使用的更多相关文章
- elasticsearch分词插件的安装
IK简介 IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包.从2006年12月推出1.0版开始, IKAnalyzer已经推出了4个大版本.最初,它是以开源项目Luen ...
- 报警插件Alertmanager 安装与使用
Alertmanager是一个独立的告警模块,接收Prometheus等客户端发来的警报,之后通过分组.删除重复等处理,并将它们通过路由发送给正确的接收器:告警方式可以按照不同的规则发送给不同的模块负 ...
- 转:ElasticSearch的安装和相关插件的安装
原文来自于:http://blog.csdn.net/whxaing2011/article/details/18237733 本文主要介绍如下内容: 1.ElasticSearch ...
- ElasticSearch head 插件安装
head 客户端可以很方便在上面创建索引,类型,文档,还有查询,使用它管理elasticsearch 提高效率. 在安装head 客户端之前必须安装node.js 环境,因为它是用node.js 编写 ...
- ubuntu安装elasticSearch及插件
原文地址:http://www.niu12.com/article/18 前提 1.安装好Java1.8以上环境并配置好JAVA_HOME(elasticsearch运行环境) 2.node环境6.5 ...
- Elasticsearch之Hadoop插件的安装(图文详解)
这个Hadoop插件的安装是非常重要. Hadoop插件安装 在es的安装目录下 bin/plugin install elasticsearch/elasticsearch-repository-h ...
- ElasticSearch 5.2.2 安装及 head 插件的安装
ElasticSearch 是一个基于 Lucene 的高度可扩展的开源全文搜索和分析引擎.它能够做到可以快速.实时地存储.搜索和分析大量数据.它通常作为底层引擎/技术,为具有复杂搜索功能和要求的应用 ...
- 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 ...
- ELK 学习笔记之 elasticsearch head插件安装
elasticsearch head插件安装: 准备工作: 安装nodejs和npm https://nodejs.org/en/download/ node-v6.11.2-linux-x64.ta ...
随机推荐
- linux服务器上面部署ShowDoc 安装Composer
1.安装Composer Composer 是 PHP 的一个依赖管理工具,功能上类似于Java 的 Maven,Python 的 pip,Ruby的 gem,Nodejs 的 npm.详细介绍可参考 ...
- 【RPC】跨语言-RPC框架
跨语言-RPC框架 跨语言 rpc_百度搜索 (5 条消息)谁能用通俗的语言解释一下什么是 RPC 框架? - 知乎 跨语言RPC框架Hessian.Thrift.Protocol Buffer之间的 ...
- R-向量
- Arrow functions and the ‘this’ keyword
原文:https://medium.freecodecamp.org/learn-es6-the-dope-way-part-ii-arrow-functions-and-the-this-keywo ...
- wamp设置自定义域名访问php网站
wamp是一个在window系统下很不错的php开发套件,一般我都是使用此套件在本地进行开发和测试的 特别是alias功能特别好,可以同时开发N个php网站而不互相影响 但alias有一个问题,它其实 ...
- [Algorithm] Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- Android权限判断checkPermission
判断本程序是否拥有某权限的方法: private static final String EXTERNAL_STORAGE_PERMISSION = "android.permission. ...
- DELL平板如何安装WIN10系统 -PE启动问题
开机按F2可以进入BIOS设置,如果你的系统已经被删了,则开机会自动进入检查程序 进入BIOS之后,可以看到如果改成Legancy,默认第一启动方式是Internal HDD 我如果重装系统, ...
- android studio开发的时候出现design editor is unavailable until after a successful project sync问题的解决方法
android studio设计界面的时候,出现了报错:design editor is unavailable until after a successful project sync,导致无法编 ...
- ZH奶酪:Git简明教程
这里是原网站:https://try.github.io/levels/1/challenges/1 这篇博文就当是笔记+翻译吧. 几个名词相关 changes:变更 repository:仓库 st ...