2.ElasticSearch预警服务-Watcher详解
编程技术  /  houtizong 发布于 3年前   88
Watcher的核心组成部分:
1.Trigger:决定何时触发,必须对每个Watcher指定
2.Input:将数据加载到Context中
3.Condition:根据条件决定师傅执行Action操作,如不设置,默认总是执行
4.Transform:可选传输设置:处理及数据Load过程设置
5.Actions:动作:零个或者多个执行动作设定
完整的案例:
PUT _watcher/watch/log_event_watch{ "metadata" : { #附加可选metedata数据 "color" : "red" }, "trigger" : { #设定一个时间计划,每5分钟执行一次 "schedule" : { "interval" : "5m" # Watcher使用系统时间,请注意保持服务器之间的时间同步 } }, "input" : { # 输入条件设定 "search" : { "request" : { #查询log-events索引中status字段为error的数据 "search_type" : "count", "indices" : "log-events", "body" : { "query" : { "match" : { "status" : "error" } } } } } }, "condition" : { #判断 错误数据是否大于5 "script" : "return ctx.payload.hits.total > 5" }, "throttle_period" : "30m", #该设定用于节流控制,简单理解为每30分钟只执行一次Action动作,避免发送大量邮件等. #默认值为5秒 "transform" : { #由于上面设置了30M发送一次,而我们5分钟执行一次查询,所有这里的设置用于更新查询结果 "search" : { "indices" : "log-events", "body" : { "query" : { "match" : { "status" : "error" } } } } }, "actions" : { #此处设置了2个Action动作 "my_webhook" : { "webhook" : {#发送数据到ES指定的索引中 "method" : "POST", "host" : "mylisteninghost", "port" : 9200, "path" : "/{{watch_id}}", "body" : "Encountered {{ctx.payload.hits.total}} errors" } }, "email_administrator" : { "email" : { #发送数据到邮件中、 "to" : "[email protected]", "subject" : "Encountered {{ctx.payload.hits.total}} errors", "body" : "Too many error in the system, see attached data", "attach_data" : true, "priority" : "high" } } }}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接