logstash自定义过滤

cat tast.conf 
input {
#在面板输入
    stdin{}
}
filter {
    grok {
#自定义的目录,只要目录,就行
        patterns_dir => ["/patterns"]
#自定义对应的 值如‘d’
        match => {
            "message" => "%{d:dong} %{c:cheng} %{j:jian}"
        }
       #overwrite => ["message"]
#如果匹配舍弃message
        remove_field => ["message"]
    }
}
output {
#在控制板输出
    stdout{        codec => rubydebug}
}

这是自定义的文件

cat patterns/dong 
d [a-zA-Z0-9._-]+
c \d+(?:\.\d+)?
j (?\d+(?:\.\d+)?)

还有一个时间戳的例子(很可能会用到)

cat tast2.conf 
input {
    stdin{}
}
filter {
    grok {
        match => ["message", "%{SYSLOGTIMESTAMP:logdate}"]
    }
    date {
        match => ["logdate", "dd/MMM/yyyy:HH:mm:ss"]
    }
    }

output {
    stdout{        codec => rubydebug}
}

logstash -f tast2.conf
使用一下看下效果
Apr 17 09:32:01(设置的是这样的时间格式)


image.png

你可能感兴趣的:(logstash自定义过滤)