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}}"
                        }
                    ]
                }
            }
        """
      }
    }
  }
}

发送结果

相关推荐
帅得不敢出门2 天前
飞书项目管理使用攻略
项目管理·飞书·开发·项目·敏捷·软件开发管理·研发管理
对酒当歌丶人生几何6 天前
ElasticSearch7.8下载、安装教程
java·elasticsearch·kibana
掘金者说9 天前
【docker】基于docker-compose 安装elasticsearch + kibana + ik分词器(8.10.4版本)
elasticsearch·docker·kibana·ik
树欲静而风不止丶13 天前
windows下安装elasticSearch和kibana
windows·elasticsearch·kibana
梁云亮14 天前
ubuntu22.04搭建elasticsearch+kibana环境
大数据·ubuntu·elasticsearch·kibana·22.04
灰色孤星A15 天前
ElasticSearch学习笔记(三)RestClient操作文档、DSL查询文档、搜索结果排序
笔记·学习·elasticsearch·微服务·kibana·es·索引
龙门吹雪16 天前
Docker 安装FileBeat、Elasticsearch及Kibana详细步骤
elasticsearch·docker·kibana·filebeat·日志监控平台
灰色孤星A16 天前
ElasticSearch学习笔记(六)自动补全、拼音分词器、RabbitMQ实现数据同步
java·笔记·学习·elasticsearch·rabbitmq·kibana·拼音分词器
装B且挨揍の1 个月前
字节跳动飞书一面0715
java·数据结构·经验分享·笔记·算法·飞书
Beiwen_1 个月前
字节-飞书人力套件-测试岗面试 题目记录
oracle·面试·飞书