1、在grok中可以使用正则来匹配相应的日志记录
%{IP:client_id_address} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:http_response_time}
grok中自带了120多种正则的匹配表达式,但个人建议还是自己根据要求去写对应的正则表达式,完全没有必要去记住grok中自带的正则表达式。
相应的在日志文件中的内容如下:
# /etc/logstash/conf.d/01-filter.conf
filter {
grok {
match => { "message" => "%{IP:client_id_address} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:http_response_time}" }
}
}
以下为日志解析的结果:
client_id_address: 55.3.244.1
method: GET
request: /index.html
bytes: 15824
http_response_time: 0.043
2、可以使用grok的自定义类型来解析
语法如下:
(?<field_name>the pattern here)