elastic_logstash
logstash_config
组成部分为: input, filter, output
文档介绍
value
A plugin can require that the value for a setting be a certain type, such as boolean, list, or hash.
Array
users => [ {id => 1, name => bob}, {id => 2, name => jane} ]
Lists
path => [ “/var/log/messages”, “/var/log/*.log” ]
uris => [ "http://elastic.co", "http://example.net" ]
Boolean
ssl_enable => true
Bytes
my_bytes => “1113” # 1113 bytes
my_bytes => "10MiB" # 10485760 bytes my_bytes => "100kib" # 102400 bytes my_bytes => "180 mb" # 180000000 bytes
Codec
codec => “json”
//更多类型https://www.elastic.co/guide/en/logstash/current/codec-plugins.html
Hash
match => {
"field1" => "value1" "field2" => "value2" ... }
Number
port => 33
Password
my_password => “password”
URI
my_uri => “http://foo:bar@example.net"
Path
my_path => “/tmp/logstash”
String
name => “Hello world”
name => 'It\'s a beautiful day'
Comments
this is a comment
1
2
3input { # comments can appear at the end of a line, too
# ...
}
filter
mutate
mutate { replace => { “type” => “file_test” } }
grok
Parses unstructured event data into fields
1
2
3grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}date
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] }
json
Parses JSON events
drop example:
1 | filter { |
input
output
filter
grok
消息解析,消息以按行为单位进行解析。基本格式为 grok { match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" } }
Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
其中,可将正则组成pattern,如”%{IP:client}” IP为pattern的类型, client为变量名,解析出来的变量如client可在后面进行使用。
自定义pattern,总结方式就是在某文件下创建pattern解析方式,如
1 | # contents of ./patterns/extra: |
再在grok中增加字段patterns_dir,patterns_dir为文件夹,非文件。如
1 | grok { |
config
config中还可以使用if条件语句,如
1 | filter { |
}
=~ 为正则匹配运算符,
EXAMPLE
file使用正则匹配
path => "/var/log/%{type}.%{+yyyy.MM.dd.HH}"
使用变量用[],如[path]
([a-zA-Z]+[.][a-zA-Z]+)[.]. 正则匹配类名
1 | json{ |
1 | #控制打印的 |
"event_type" => "%{[jsoncontent][type]}"
"event_msg" => "%{[jsoncontent][event]}"
}
}
} else {
drop { }
}
Example
filter-aggregate
1 | input { |
1 | # } |
filter-basic-grok
1 | input { |
1 | # if ([producer] !~ /[m].*/ or "_grokparsefailure" in [tags]) { |
1 | } |
坑
调式过程中出现解析文件没报错也没任何的东西…
logstash会监听文件读取信息记录的位置,所以解析过的文件,如果文件内容并没有发生变化(暂且说是内容吧,可能logstash只能监听位置改变而不能识别之前内容有所改变,这个我还未验证过..),那么再次解析的话,将不会解析以前解析过的内容。解决方式是将监听的记录删掉,记录存在于{logstash}/data/plugins/inputs/file/.sincedb*