# ESAlert **Repository Path**: yunwe/esalert ## Basic Information - **Project Name**: ESAlert - **Description**: 监控Elasticsearch索引内的日志,通过添加告警项推送告警至指定平台 - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-04-25 - **Last Updated**: 2025-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: 监控, ElasticSearch, 日志, Go语言 ## README # ESAlert ## 介绍 该项目主要实现对Elasticsearch上传的服务日志内容进行告警,需要日志索引配置timestamp或其他type为time类型的字段。 ## 功能说明 ### 历史告警保存 是否开启历史告警保存功能可自行在配置文件调整 ### 告警推送 1、通过暴露metric,使用Prometheus进行数据抓取,自行配置告警及监控。 2、平台自带推送。 ## 安装 推荐直接下载gitee构建好的可执行文件 ### 构建(可选) ```shell git clone https://gitee.com/yunwe/esalert.git cd esalert # 设置国内代理(七牛云) go env -w GOPROXY=https://goproxy.cn,direct # 构建x86_64版本 GOOS=linux GOARCH=amd64 go build -o esalert_amd64_linux ./app # 构建arm版本 GOOS=linux GOARCH=arm64 go build -o esalert_arm64_linux ./app ``` ### 容器构建(可选) ```shell git clone https://gitee.com/yunwe/esalert.git docker build -t registry.cn-hangzhou.aliyuncs.com/huang-image/esalert:${version} . ``` ### 配置文件说明 以nginx日志为例: ```yaml #带有默认参数的可不填写,其他为必填项 - alert: "测试规则1" timeRange: 10 #查询时间范围,默认10分钟 index: "catalina-*" #指定索引名,使用 * 支持模糊匹配 frequency: 1 #探测频率,n分钟一次,默认1分钟1次 filed: #查询支持Lucene语法,关于Lucene语法教程请看: https://lucenetutorial.com/lucene-query-syntax.html a: "status: 404" #对查询结果进行变量赋值,从而实现多条结果比对,比如status:404赋值给变量a,status:200赋值给变量b,判断A是否大于B。 b: "status: 200" trigger: "a > b" # 如果A大于B则触发告警 - alert: "测试规则2" timeRange: 5 index: "nginx-*" frequency: 2 filed: a: "error AND warning" trigger: "a > 10" ``` > **Lucene简单使用:** > > 它支持多种操作符,如AND、OR、NOT等,可以用来组合多个查询条件,以便更精确地搜索文档。例如,你可以使用以下查询字符串来搜索状态为200或400且包含关键字"error"的文档:`(status:200 OR status:400) AND error` > > 这个查询字符串中包含两个部分:`(status:200 OR status:400)`和`error`。两个部分之间使用`AND`操作符连接,表示两个条件都必须满足。