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

  多調試,肯定不會立刻成功的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM