Logstash 实践之Redis日志解析

本文介绍了如何使用Logstash进行Redis集群日志的解析,包括logstash配置脚本和样例日志的解析输出,重点展示了Grok正则表达式的应用。
摘要由CSDN通过智能技术生成

Logstash 实践之Redis日志解析

logstash config 脚本配置

input {
    file {
        path => ["/apps/svr/logstash/log/redis1.log"]
        start_position => "beginning"
        type => "redis_cluster"
    }
}

filter {
    multiline {
        what => next
        pattern => "^(?!(\d)+).*$"
    }
    grok {
        match => ["message", "(?<pid>.\d+?):(?<role>\w?)\s+(?<log_time>%{MONTHDAY}\s+%{MONTH}\s+%{HOUR}:%{MINUTE}:%{SECOND}?)\s+(?<log_level>.?)\s%{GREEDYDATA:message}"]
        overwrite => ["message"]
    }

    if [log_level] == "*" {
        mutate{ update => {
  "log_level" => "NOTICE"}}
    }

    if [log_level] == "#" {
        mutate{ update => {
  "log_level" => "WARNING"}}
    }

    if [log_level] == "-" {
        mutate{ update => {
  "log_level" => "VERBOSE"}}
    }

    if [log_level] == "." {
        mutate{ update => {
  "log_level" => "DEBUG"}}
    }
}
output {
    stdout {
        codec => rubydebug
    }

}

grok的正确性可以在该网站检验Grok Test

Sample redis cluster log

230186:M 07 Jan 14:10:31.137 # Bad message length or signature received from Cluster bus.
230186:M 07 Jan 14:14:10.291 * FAIL message received from a36530f8df368550c186d9d8a2c5e39d3afe9b65 about 3d8bdc2e000031eb1f30f885d8a58fed4be270ed
230186:M 07 Jan 14:14:45.131 * Clear FAIL state for node 3d8bdc2e000031eb1f30f885d8a58fed4be270ed: is reachable again and nobody is serving its slots after some time.
230186:M 07 Jan 14:15:27.525 # Bad message length or signature received from Cluster bus.
230186:M 07 Jan 14:15:27.525 # Bad message length or signature received from Cluster bus.
230186:M <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值