good luck! ------ 博客

filebeat v6.3 多行合并的步骤 多个表达式同时匹配

配置文件位于/etc/filebeat/filebeat.yml,就是filebeat的主配置文件
打开文件filebeat.yml,搜索multiline:,默认是注释的,常用的有如下三个配置:

multiline.pattern: '^\<|^[[:space:]]|^[[:space:]]+(at|\.{3})\b|^Caused by:'  #正则,自己定义,一个表示可以匹配多种模式使用or 命令也就是“|”

multiline.negate: false #默认是false,匹配pattern的行合并到上一行;true,不匹配pattern的行合并到上一行

multiline.match: after #合并到上一行的末尾或开头

#优化参数

multiline.max_lines: 500 #最多合并500行

multiline.timeout: 5s #5s无响应则取消合并

 

 

  总的来说,multline 是模块名,filebeat爬取的日志满足pattern的条件则开始多行匹配,negate 设置为false 是需要的,因为我们的多行语句都需要连着上一行,match 合并到末尾。

  由于正则表达是你需要实际匹配你自己想要满足的条件,如果直接fillebet 调试,会非常麻烦,可以参考下面这个地址

多行合并的正则表达式测试地址:http://play.flysnow.org/

  附上我的调试脚本,看着一下pattern和content就可以

   

package main

import (
	"fmt"
	"regexp"
	"strings"
)
var pattern = `^[[:space:]]`
var
var negate = false

var content = `放入自己的内容`

func main() {
	regex, err := regexp.Compile(pattern)
	if err !=nil {
		fmt.Println("Failed to compile pattern: ", err)
		return
	}
	
	lines := strings.Split(content, "\n")
	fmt.Printf("matches\tline\n")
	for _, line := range lines{
		matches := regex.MatchString(line)
		if negate {
			matches = !matches
		}
		fmt.Printf("%v\t%v\n", matches, line)
	}
	
	
	
}

  

最后附上官网地址:https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html

  多调试,肯定不会立刻成功的。

 

posted @ 2019-02-13 16:35  木直  阅读(3182)  评论(0编辑  收藏  举报