Logstash Filter解析Openrety的Log数据的简单配置

1.2k 词

作者:糖果

Logstash的配置文件位置:/etc/logstash, 而logstash本身的程序,可以放到别的定制的位置。

一般性的Logstash配置有三个节:

input {
file {
        path => "/test/log/567/*.log"
        type => "nginx" # a type to identify those logs (will need this later)
}
}

filter {
if [type] == "nginx" { # this is where we use the type from the input section
        grok {
                match => [ "message", "COMBINEDNGINXLOG" ]
        }
}
}

output {
        elasticsearch {
                hosts => ["127.0.0.1:9200"]
                index => "testdata"
}

}

第一个节:
input用于指定log文件的位置和类型。

input {
file {
        path => "/test/log/567/*.log"
        type => "nginx" # a type to identify those logs (will need this later)
}
}

第二节:
filter指定log文件指段配置的Pattern,关键分词就靠这个。

filter {
if [type] == "nginx" { # this is where we use the type from the input section
        grok {
                match => [ "message", "COMBINEDNGINXLOG" ]
        }
}
}

第三节:
output指定log转换后的数据存储和位置,下面的设置是典型的输出到ES中。

output {
        elasticsearch {
                hosts => ["127.0.0.1:9200"]
                index => "testdata"
}

}

grok filter的官吏法可以参考这篇: 参考文

COMBINEDNGINXLOG实际是没有这个pattern的,只有占位用的。