我用的是filebeat,
input {
beats {
port => 5783
}
}
filter {
json {
source => "message"
}
}
output {
elasticsearch {
hosts => [ "xxx:9200","xxxxx:9200" ]
index => "nginxaccesslog-%{+YYYY.MM.dd}"
}
nginx輸出要開json格式,不然你搞grok會搞很久,不要問我爲什麼,如果你的正則very good,那麼當我沒說。
如果你解析完了以後要吧message給remove掉,那麼很簡單,mutate很容易做到這點:
if [event][dataset] !="nginx.error" {
mutate {
remove_field => ["message"]
}
}
mutate一般結合if來做,
https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html
if EXPRESSION {
...
} else if EXPRESSION {
...
} else {
...
}
就跟c語法一摸一樣,表達式裏面支持的運算有三類,
You can use these comparison operators:
equality: ==, !=, <, >, <=, >=
regexp: =~, !~ (checks a pattern on the right against a string value on the left)
inclusion: in, not in
Supported boolean operators are:
and, or, nand, xor
Supported unary operators are:
!
這東西還是強大,一個dsl語言,所以還是需要一定的學習成本。我一直覺得技術迭代是一方面,當你熟悉了某個技術以後再去用另一個,學習成本是一定要考慮的要素,除非你的學習能力超強或者是團隊有其他人support,否則大部分人還是會選擇他熟悉的技術棧。
官網還提供了比較詳盡的pipeline語法,
https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html
忘了看看還是挺有必要的。