文档

通过logstash进行日志关键字监控

本文档介绍通过logstash,结合运维事件中心的标准集成,进行日志关键字监控。

日常运维过程中,很多场景都会有诉求,需要对日志关键字进行监测,以便第一时间发现应用/业务相关异常,如jvm日志的gc关键字、业务日志的error关键字。本文档将使用logstash对异常日志进行采集及推送。

日志构造

为了便于说明,本文档将以不断打印如下test.log进行验证、演示。

2021-08-11T00:34:06+08:00 in shanghai,tradeplatform occur P1 ,112.11.123.11keywords error,message:Warning tradeplatform has some exception,content service exception;envirment type:online;group:aliyun;tags:xxxxx

日志推送至标准集成

1. 下载并安装logstash组件。

2. 修改logstash配置文件,对异常日志进行推送。logstash.conf配置文件参考如下:

input {
        beats {
                port => 5044
        }
  
        file {
                path => "/home/test.log"
  type => "test"
        }
}

filter {
    if [type]=="test" {
        grok {
                match => {
   "message" => "%{TIMESTAMP_ISO8601:timestamp} in %{DATA:region},%{DATA:application} occur %{DATA:level},%{IPV4:source}%{DATA:name},message:%{DATA:summary},content%{DATA:details};envirment type:%{DATA:class};group:%{DATA:group};tags:%{DATA:tag}"
                }
        }
 mutate {
                remove_field => ["host"]
                remove_field => ["@version"]
                remove_field => ["@timestamp"]
                remove_field => ["path"]  
                remove_field => ["message"]
        }
    }
}

output {
    if [type]=="test" {
        http {
                url => " 请替换为标准集成中的URL "
                http_method => "post"
                format => "json"
        }
    }

}
重要

上述的URL为标准集成的对接URL,可至运维事件中心控制台集成中心>集成配置>标准集成里获取格式类似为:https://public-alert.aliyuncs.com/event/standard/8cd0b46766dd4e2488a5cd5663xxxxxx

3. 启动logstash,开始将异常日志推送至运维事件中心。

4. 为了便于标准集成中查看对应数据格式,本示例手动造一条日志,执行以下命令即可。

echo '2021-08-11T00:34:06+08:00 in shanghai,tradeplatform occur P1 ,112.11.123.11keywords error,message:Warning tradeplatform has some exception,content service exception;envirment type:online;group:aliyun;tags:xxxxx' >> test.log 

集成配置及流转

1. 在运维事件中心控制台集成中心>集成配置>标准集成查看最新推送的数据记录。

日志集成1

2. 在策略中心>流转规则里新增对应的规则,由于日志error是核心异常场景,此处示例优先级选择P1、个人通知勾选电话通知。

日志集成2日志集成3

3. 为了便于演示,本示例手动造一条日志,以便生成对应事件,执行以下命令即可。

echo '2021-08-11T00:34:06+08:00 in shanghai,tradeplatform occur P1 ,112.11.123.11keywords error,message:Warning tradeplatform has some exception,content service exception;envirment type:online;group:aliyun;tags:xxxxx' >> test.log 

4. 在运维事件中心控制台的事件中心>事件,即可看到最新推送告警所生成的事件。同时分派对象会接收到对应的电话、短信、邮件通知。

日志集成4日志集成5

其他

以上为如果通过logstash进行日志推送,并在运维事件中心中配置对应关键字,以便准确生成对应事件进行流转处理。实际场景中,也可通过其他技术手段实现推送,如将logstash替换为filebeat等常见开源日志组件、应用程序打印日志通过Shell脚本进行读取并推送等。

  • 本页导读 (0)
文档反馈