如何使Logstash多行过滤器基于某些动态字段值合并行?

如何使Logstash多行过滤器基于某些动态字段值合并行?,logstash,logstash-grok,logstash-configuration,elastic-stack,logstash-file,Logstash,Logstash Grok,Logstash Configuration,Elastic Stack,Logstash File,我对logstash是个新手,希望能为其中一个用例设置ELK。我发现这个问题与我的有关 如果多行过滤器不合并grok字段上的行,那么如何合并下面日志示例中的第2行和第10行?请帮忙 使用grok模式,我创建了一个保存值715的字段“id” Line1 - 5/08/06 00:10:35.348 [BaseAsyncApi] [qtp19303632-51]: INFO: [714] CMDC flowcxt=[55c2a5fbe4b0201c2be31e35] method=contentde

我对logstash是个新手,希望能为其中一个用例设置ELK。我发现这个问题与我的有关 如果多行过滤器不合并grok字段上的行,那么如何合并下面日志示例中的第2行和第10行?请帮忙

使用grok模式,我创建了一个保存值715的字段“id”

Line1 - 5/08/06 00:10:35.348 [BaseAsyncApi] [qtp19303632-51]: INFO: [714] CMDC flowcxt=[55c2a5fbe4b0201c2be31e35] method=contentdetail uri=http://10.126.44.161:5600/cmdc/content/programid%3A%2F%2F317977349~programid%3A%2F%2F9?lang=eng&catalogueId=30&region=3000~3001&pset=pset_pps header={}   
Line2 - 2015/08/06 00:10:35.348 [BaseAsyncApi] [qtp19303632-53]: INFO: [715] CMDC flowcxt=[55c2a5fbe4b0201c2be31e36] method=contentdetail uri=http://10.126.44.161:5600/cmdc/content/programid%3A%2F%2F1640233758~programid%3A%2F%2F1073741829?lang=eng&catalogueId=30&region=3000~3001&pset=pset_pps header={}   
Line3 - 2015/08/06 00:10:35.349 [TWCAsyncProcessor] [TWC-pool-3-thread-2]: INFO: [714:426] TWC request=MercurySortRequest   
Line4 - 2015/08/06 00:10:35.349 [TWCAsyncProcessor] [TWC-pool-3-thread-1]: INFO: [715:427] TWC request=MercurySortRequest   
Line5 - 2015/08/06 00:10:35.352 [BaseAsyncApi] [qtp19303632-54]: INFO: [716] CMDC flowcxt=[55c2a5fbe4b0201c2be31e37] method=contentdetail uri=http://10.126.44.161:5600/cmdc/content/programid%3A%2F%2F2144942810~programid%3A%2F%2F1953281601?lang=eng&catalogueId=30&region=3000~3001&pset=pset_pps header={}   
Line6 - 2015/08/06 00:10:35.354 [TWCAsyncProcessor] [TWC-pool-3-thread-1]: INFO: [716:428] TWC request=MercurySortRequest   
Line7 - 2015/08/06 00:10:35.359 [BaseAsyncApi] [qtp19303632-49]: INFO: [717] CMDC flowcxt=[55c2a5fbe4b0201c2be31e38] method=contentdetail uri=http://10.126.44.161:5600/cmdc/content/programid%3A%2F%2F2144942448~programid%3A%2F%2F2147355770?lang=eng&catalogueId=30&region=3000~3001&pset=pset_pps header={}   
Line8 - 2015/08/06 00:10:35.360 [TWCAsyncProcessor] [TWC-pool-3-thread-2]: INFO: [717:429] TWC request=MercurySortRequest   
Line9 - 2015/08/06 00:10:35.366 [TWCAsyncProcessor$TWCAsyncProcessorCallback$ReceiveCallback] [CMDC-pool-2-thread-41]: INFO: [715:427] TWC response status=200 hits=1 time=17 internal=10.42   
Line10 - 2015/08/06 00:10:35.367 [BaseAsyncApi] [CMDC-pool-2-thread-41]: INFO: [715] CMDC response status=200 CMDC=19ms TWC=17ms #TWC=1

您需要使用设置了
流标识的
多行
过滤器。文档中不清楚它的用途,但您的基本策略如下:

if (!"multiline" in [tags]) {
  grok { // parse out your identity field }
  multiline { 
    stream_identity => "%{id}"
    pattern => "." // match anything because we're gathering by id field
    what => "previous"
    periodic_flush => true
    max_age => 5 // however many seconds it takes to get all of your lines together
    add_tags => ["multiline" ]
  }
} else {
  // process multiline event that's been flushed
}

自1.5问世以来,我从未尝试过类似的方法,但文档说它应该可以工作(在1.4.2及之前版本中,刷新机制不起作用,因此可能会丢失事件)。

感谢您的回答。你的建议行得通,我可以合并这些行。我正在做一个poc,看看麋鹿是如何为我们工作的。我还遇到了一个问题,即冲洗可能会导致信息碎片。目前,我正在处理静态测试数据,并没有遇到这个问题。这里有Mulitline的替代版本()。我必须试一试。我相信冲洗机制是在1.4.2和1.5之间“固定”的。在1.4.2中,冲洗为实验性冲洗,并以固定速率(即每5秒)冲洗一次。。。我认为在较新的版本中,它是基于最长时间进行刷新的——即上次事件添加新行后的几秒钟。我认为在大多数情况下,这样做很好。我还曾经写过一个多行固定插件——如果你知道第一行和最后一行是什么样子的,当它到达最后一行时,它会刷新——不过我现在还不能动手:)