Kibana使用Watcher监控服务日志并发送飞书报警(Markdown)

Watcher是什么

Kibana Watcher 是 Elasticsearch 的监控和告警工具,它允许你设置和管理告警规则以监控 Elasticsearch 数据和集群的状态。Kibana Watcher 可以监测各种指标和数据,然后在满足特定条件时触发警报。它提供了一种强大的方式来实时监控 Elasticsearch 数据、集群性能、日志和事件,以及其他关键指标。

构造飞书报警内容

创建飞书群聊并添加飞书报警机器人, 获取Webhook地址


构造请求体

json 复制代码
{
    "msg_type": "interactive",
    "card": {
        "header": {
            "template": "red",
            "title": {
                "tag": "plain_text",
                "content": "接口请求预警(20m)"
            }
        },
        "config": {
            "wide_screen_mode": true,
            "enable_forward": true
        },
        "elements": [
            {
                "tag": "markdown",
                "content": "**接口:** /lastVersion\n**预警值:** 1000\n**请求次数:** 10000"
            }
        ]
    }
}

添加Watcher

入口: Stack Management -> Watcher -> Create

2种方式:

Create threshold alert: 一般用于简单的指标监控, 及Index数量统计

Create advanced watch: 高级预警, 用于创建更复杂和灵活的监控规则。

此时我们选Create advanced watch

Name为Watcher名称, 用于标识

ID为自动生成, 也可编辑

Watch JSON为具体配置, 示例如下:

json 复制代码
{
  "trigger": { // 触发时间
    "schedule": {
      "interval": "10m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [ // 索引
          "*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "track_total_hits": true, // 精确查找个数
          "query": { // 查询近30min的/lastVersion请求次数
            "bool": {
              "must": {
                "match": {
                  "message": "/lastVersion"
                }
              },
              "filter": {
                "range": {
                  "@timestamp": {
                    "from": "{{ctx.trigger.scheduled_time}}||-30m",
                    "to": "{{ctx.trigger.triggered_time}}"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": { // 触发条件
    "compare": {
      "ctx.payload.hits.total": { // 总数大于25w触发action
        "gte": 250000
      }
    }
  },
  "actions": {
    "feishu_webhook": { // 飞书报警
      "webhook": {
        "scheme": "https",
        "host": "open.feishu.cn",
        "port": 443,
        "method": "post",
        "path": "/open-apis/bot/v2/hook/**********",
        "params": {},
        "headers": {},
        "body": """
            {
                "msg_type": "interactive",
                "card": {
                    "header": {
                        "template": "red",
                        "title": {
                            "tag": "plain_text",
                            "content": "接口请求预警(30m)"
                        }
                    },
                    "config": {
                        "wide_screen_mode": true,
                        "enable_forward": true
                    },
                    "elements": [
                        {
                            "tag": "markdown",
                            "content": "**接口:** /lastVersion\n**预警值:** 200000\n**请求次数:** {{ctx.payload.hits.total}}"
                        }
                    ]
                }
            }
        """
      }
    }
  }
}

发送结果

相关推荐
xiezhr10 天前
折腾半小时,终于让AI 能直接帮我写飞书文档了
ai·飞书·ai agent·飞书cli·飞书文档
Markland_l16 天前
从dify、coze、飞书、obsidian看rag架构
架构·飞书
zyplayer-doc18 天前
继飞书之后,又一款知识库推出了开源 Agent-Native CLI 工具
人工智能·pdf·编辑器·飞书·开源软件
旺财矿工18 天前
OpenClaw 飞书机器人配置教程|一键对接飞书,实现聊天下达 AI 指令
人工智能·机器人·飞书·openclaw·龙虾
程序猿小白菜18 天前
OpenClaw 飞书机器人搭建流程
ai·机器人·飞书·openclaw
x-cmd18 天前
[260612] x-cmd v0.9.8:x feishu 发送消息支持 Markdown + 卡片,让 x claw 接入飞书后消息不再干巴巴
飞书·agent·claude·命令行·x-cmd·openclaw
诗词在线18 天前
专业的飞花令网站
飞书
河北小博博20 天前
OpenClaw 接入飞书 / 钉钉 / 企业微信:从 HTTP Webhook 到 WebSocket 长连接
钉钉·飞书·企业微信
蜀道山老天师21 天前
OpenClaw 从零部署 + 飞书机器人完整接入(实操篇)
运维·docker·容器·飞书
花伤情犹在21 天前
Hermes 清理飞书会话操作指南
linux·sqlite·飞书·agent·hermes