ELK系列x-pack监控错误日志并配置钉钉报警

本文章基于elk版本6.7.0监控错误日志

安装ELK和xpack安装破解略过,可以参考另一篇博客

https://blog.csdn.net/qq_43076479/article/details/106349348

配置Nginx代理

server
  {
    listen 8080;#监听端口
    server_name localhost;#域名
    index index.html index.htm index.php;
    root /usr/local/webserver/nginx/html;#站点目录
      location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
      # access_log off;
    }
    location / {
      proxy_pass <钉钉机器人Webhook地址>;
    }
    location ~ .*\.(js|css)?$
    {
      expires 15d;
      # access_log off;
    }
    access_log off;
  }

启动nginx,查看监听端口

钉钉创建机器人步骤略过 

配置x-pack报警规则

登录kibana平台

在左侧菜单栏,单击Dev Tools(开发工具)

在Console中执行如下命令创建一个报警文档

以下示例以创建log_error_watch为例,每隔15s查询sdtomcatlog_2020.09索引中是否出现ERROR日志,如果出现0次以上则触发报警,报警规则1分钟以内没有处理则继续报警,配置需要按需修改

PUT _xpack/watcher/watch/log_error_watch
{
  "trigger": {
    "schedule": {
      "interval": "15s"
    }
  },
  "input": {
    "search": {
      "request": {
        "indices": ["sdtomcatlog_2020.09"],
        "body": {
          "query": {
            "match": {
              "level": "ERROR"
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gt": 0
      }
    }
  },
  "actions" : {
  "test_issue" : {
    "throttle_period": "1m",
    "webhook" : {
      "method" : "POST",
      "url" : "http://10.4.7.102:8080",
      "body" : "{\"msgtype\": \"text\", \"text\": { \"content\": \"快汇通项目error 日志出现了,请在1分钟内使用elastic用户在kibana平台的Dev Tools操作栏执行确认操作:PUT  _xpack/watcher/watch/log_error_watch/_ack/test_issue\"}}"
    }
  }
}
}

告警示意图如下,内容可自定义

告警出现后我们需要在kibana平台的左侧菜单栏,单击Dev Tools(开发工具),执行报警内容的确认操作,

PUT _xpack/watcher/watch/log_error_watch/_ack/test_issue

处理完并把错误日志删除:

POST /sdtomcatlog_2020.09/_delete_by_query   
{
 "query": { "match": { "level": "ERROR" } }
}

删除索引的所有错误日志

查看报警规则状态:

GET _xpack/watcher/watch/log_error_watch

只有在这个状态下才会继续监控错误日志,前提是记得把前边的错误日志都删除才会自动恢复此状态。

body可自定义报警内容,例如:

 "body" : "{\"msgtype\": \"text\", \"text\": { \"content\": \" 日志告警\n 日志条数: {{ctx.payload.hits.total}}\n 机器名称: {{ ctx.payload.hits.hits.0._source.host.name }}\n 日志路径: {{ ctx.payload.hits.hits.0._source.source }}\n 实例ID:{{ ctx.payload.hits.hits.0._source.meta.cloud.instance_id }}\n 报错日志:\n{{#ctx.payload.hits.hits}}{{_source.message}}\n {{/ctx.payload.hits.hits}}\"}}"

 

 

 

 

 

 

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值