zoukankan      html  css  js  c++  java
  • es上的的Watcher示例

    Watcher插件配置(创建预警任务)

    watcher目前是沒有界面配置的,需要通过Resfulapi调用创建、管理、更新预警任务

    创建一个Watcher任务的流程是怎样的?

    我们先来看下创建一个预警demo的api

    复制代码
    curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '
    { "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": [ "monitor_ticket_bargainfindermaxrq_201610" ], "body": { "query": { "bool": { "must": [ { "match": { "collectionName": "BargainFinderMaxRQ" } }, { "range": { "createTime": { "gt" : "now-1m" } } } ] } } } } } }, "condition": { "compare": { "ctx.payload.hits.total": { "gt": 20 } } }, "actions": { "send_email": { "email": { "to": "xxxxxx@xxx.com", "subject": "TICKET_BFM 過去一分鐘內錯誤發生次數超過20,請關注", "body": "TICKET_BFM 過去一分鐘內錯誤發生次數超過20,請關注" } } } }'
    复制代码

    当然actions里面还支持模板,比如

    复制代码
    "actions": {
            "send_email": {
                "email": {
                    "to": "xxx@xxx.com",
                    "subject": "TICKET_BFM 過去一分鐘內錯誤發生{{ctx.payload.hits.total}}次數超過20,請關注",
                    "body": "TICKET_BFM:{{ctx.watch_id}}  過去一分鐘內錯誤發生{{ctx.payload.hits.total}}次數超過20,請關注 Happened at {{ctx.execution_time}}"
                }
            }
        }
    复制代码

    从api的content我們可以看出,內容主要主体分成trigger(触发设置),input(来源设置),condition(条件),actions(触发动作设置)

    这里我们设置触发间隔时间为1m,来源是monitor_ticket_bargainfindermaxrq_201610索引块,查询条件是collectionName字段值是BargainFinderMaxRQ,以及时间范围是过去1分钟到现在,然后触发条件是当数量大于20,动作设置的是发邮件

    Action类型其实有4种,EMail(邮件),Webhook(第三方对接),Index(索引),Logging(日志记录),相关配置可以参考下官方文档

    如果配置了发送邮件,那么需要在es的yml文件配置下邮件发送服务器

    我这里设置的是公司的服务器

    watcher.actions.email.service.account:
      work:
        profile: standard
        email_defaults:
          from: '<yourname>@xx.com'
        smtp:
          auth: true
          starttls.enable: true
          host: smtp.xx.com
          port: 25
          user: yourname@xx.com
          password: password

    注:设置之后重启下es服务器

  • 相关阅读:
    利用 PHP 导出 Git 某个分支下,新增或修改过的文件
    [翻译] 10 个实用的 Git 高级命令
    Django web project
    install virtualenv
    js原型继承
    HTML 学习杂记
    IDEA 文件列表隐藏某后缀文件
    coocsCreator杂记
    mac install brew
    c编程:输入一个数字n,则n代表n行,每行输入2个数字a,b计算每行的a+b问题。
  • 原文地址:https://www.cnblogs.com/bigben0123/p/10309923.html
Copyright © 2011-2022 走看看