ElasticSearch预警服务-Watcher安装指南及案例介绍
编程技术  /  houtizong 发布于 3年前   77
本文将介绍如何安装Watcher服务,并介绍相关的功能特征。
1.Watcher服务的安装
目前Watcher服务处于Beta阶段,使用者可以申请最新的beta-key,然后通过插件的方式进行安装
bin/plugin -i elasticsearch/watcher/<watcher-beta-key>
2.验证服务
curl -XGET 'http://192.168.100.72:9200/_watcher/stats?pretty'或者直接通过浏览器访问也是可以的
3.版本要求
Watcher需要ElasticSearchV1.5.0+版本
案例介绍一:
监控错误数据案例,每10秒搜索一次数据,发现错误后,记录一条错误记录。
配置流程:
1.设置定时器和输入源(错误数据的查询条件)
2.设置触发条件(是否查询到了错误数据)
3.设置触发动作(发现错误后执行Action)
设置详情:
1.每10秒搜索一次日志数据
curl -XPUT 'http://192.168.100.72:9200/_watcher/watch/log_error_watch' -d '{ "trigger" : { "schedule" : { "interval" : "10s" } }, "input" : { "search" : { "request" : { "indices" : [ "logs" ], "body" : { "match" : { "message": "error" } } } } }}'
2.数据加载情况历史记录
curl -XGET 'http://192.168.100.72:9200/.watch_history*/_search?pretty' -d '{ "sort" : [ { "execution_result.execution_time" : "desc" } ]}'
从返回结果中可以看到每10秒触发一次查询操作,如果历史记录中无数据,表示没有搜索到数据。
3.如何设置条件
curl -XPUT 'http://192.168.100.72:9200/_watcher/watch/log_error_watch' -d '{ "trigger" : { "schedule" : { "interval" : "10s" } }, "input" : { "search" : { "request" : { "indices" : [ "logs" ], "body" : { "query" : { "match" : { "message": "error" } } } } } }, "condition" : { #设置条件,结果数据是否大于0!即是否查询到了数据 "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} }}'
3.查询触发条件执行状态
#查询Watcher的历史记录,验证触发条件是否被触发了curl -XGET 'http://192.168.100.72:9200/.watch_history*/_search?pretty' -d '{ "query" : { "bool" : { "must" : [ { "match" : { "execution_result.condition.met" : true }}, { "range" : { "execution_result.execution_time" : { "from" : "now-10s"}}} ] } }}'
4.设置动作
curl -XPUT 'http://192.168.100.72: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" : { #触发动作,这里可以使 记录日志,发送邮件,发送到第三方的WebHook等等。 "log_error" : { "logging" : { "text" : "Found {{ctx.payload.hits.total}} errors in the logs" } } }}'
案例介绍二:
监控ElasticSearch集群状态:每10秒检测一次集群状态,如果集群状态错误,则发送邮件给运维
配置流程就不过多介绍了,直接来结果。
curl -XPUT 'http://192.168.100.72:9200/_watcher/watch/cluster_health_watch' -d '{ "trigger" : { "schedule" : { "interval" : "10s" } }, "input" : { "http" : { "request" : { "host" : "192.168.100.72", "port" : 9200, "path" : "_cluster/health" } } }, "condition" : { "compare" : { "ctx.payload.status" : { "eq" : "red" } } }, "actions" : { "send_email" : { "email" : { "to" : "[email protected]", "subject" : "ES Cluster Status Warning", "body" : "ES Cluster status is RED" } } }}'请注意,如果配置邮件发送,需要在ElasticSearch配置文件中配置以下信息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>
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接