[英]Parse my business_log using grok filter (Logstash)
我的business_log
某些行:
2016-11-28 00:00:00.7000 INFO : OneTwoThreeHandler.GetBot
Cannot find a bot: Rak 20000
2016-11-28 00:00:00.7000 INFO : OneTwoThreeHandler.GetBotPlayer
Cannot find a bot: COIN 50000
2016-11-28 00:00:01.4812 INFO : OneTwoThreeHandler.GetBotPlayer
Find a bot: 1219552640:ut:coinu - rak: 6703098 - coin: 2721975
2016-11-28 00:00:01.4812 INFO : OttMatchSolo.Matched
Solo Matched: 1:Rak
我想根据“关键字”来解析此日志,例如OneTwoThreeHandler.GetBot
, OneTwoThreeHandler.GetBotPlayer
, OneTwoThreeHandler.GetBotPlayer
或OttMatchSolo.Matched
。
因为对于每个“关键字”,行日志的其余部分都是不同的。 我认为我可以使用grok条件句,有人可以告诉我如何做吗? 谢谢
您可以这样做,假设message
字段包含您的日志:
if [message] =~ /OneTwoThreeHandler\.GetBotPlayer/ {
...
} else if [message] =~ / OneTwoThreeHandler\.GetBot/ {
...
} else if [message] =~ /OttMatchSolo\.Matched/ {
...
} else {
...
}
每个分支都包含针对那些特定日志的特定配置。
有关logstash配置中条件的更多信息,请参见本文档 。
您需要将日志通过多行过滤器/编解码器进行处理,或者对托运人进行操作,以使日志位于一行上,如下所示:
2016-11-28 00:00:01.4812 INFO : OttMatchSolo.Matched Solo Matched: 1:Rak
或者您可以在一个grok过滤器中放置多个grok模式:
grok{
match => {
"message" => [
"%{TIMESTAMP_ISO8601} %{LOGLEVEL} : OneTwoThreeHandler.GetBotPlayer %{GREEDYDATA}",
"%{TIMESTAMP_ISO8601} %{LOGLEVEL} : OneTwoThreeHandler.GetBot %{GREEDYDATA}",
"%{TIMESTAMP_ISO8601} %{LOGLEVEL} : OttMatchSolo.Matched %{GREEDYDATA}"
]
}
}
您仍然需要执行多行联接才能起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.