Logstash 父子关系 配置
生活随笔
收集整理的這篇文章主要介紹了
Logstash 父子关系 配置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
最近在使用Lostash的過程中遇到了一個問題:在一個log文件里包含兩類數(shù)據(jù),而且兩類數(shù)據(jù)之間存在父子關(guān)系,那如何使用lostash的configuration實現(xiàn)這個需求呢
思路:
在此要感謝elastic官方論壇的一個帖子:"keep global variable in logstash",它讓我知道了如何使用filter->ruby來實現(xiàn)全局變量。
以下是logstash的完整配置?
input {beats {port => 5044} }filter { # remove the empty linesif [message] =~ /^\s*$/ {drop { }}# define parent event patterngrok {match => {"message" => "%{DATESTAMP:EventTime},%{NUMBER:Mil:INT} %{WORD:Type} %{GREEDYDATA:Item} %{GREEDYDATA:RIC} %{GREEDYDATA:Detail} %{GREEDYDATA:Category}"}}# children eventsif "_grokparsefailure" in [tags] {grok {match => {"message" => "\<%{NUMBER:FID:INT}\>,%{GREEDYDATA:FName},%{WORD:FType},%{GREEDYDATA:FValue}"}add_field => {"DocID" => '' "ParentID" => ''}add_tag => ["%{FType}"]remove_tag => ["_grokparsefailure"]}ruby {code => "require 'digest/md5';event['ParentID'] = @@parentid;event['DocID'] = Digest::MD5.hexdigest(@@parentdate+event['FID'])"}}else{mutate {add_field => {"DocID" => ''}add_tag => ["parent"]}# define a global variable to keep the parent id# must set the default value for the variables in ruby -> init block, or it will raise exceptionruby {init => "@@parentid = '';@@parentdate=''"code => "require 'digest/md5';@@parentid = Digest::MD5.hexdigest(event['EventTime']+event['Mil']);event['DocID'] = @@parentid;@@parentdate = event['EventTime']+event['Mil']"}}#remove the redundant fields created by filebeat. you can ignore it if you don't use filebeat as shipper mutate {remove_field => ["[beat][hostname]","[beat][name]","count","fields","input_type","offset","type","beat","@version"]} }output {elasticsearch {hosts => ["localhost:9200"]index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"#set the document_iddocument_id => %{"DocID"}document_type => "%{[@metadata][type]}"#template => "/appserver/ELK/logstash-2.3.4/conf/template_tolreport.json"#template_name =>"template_tolreport"#template_overwrite => true}# file {# path => "./test-%{+YYYY-MM-dd}.txt"# } }英語好的同學(xué)可以參考我在elastic 的官方論壇中發(fā)的帖子:https://discuss.elastic.co/t/logstash-parent-child-event-configuration/58117
轉(zhuǎn)載于:https://www.cnblogs.com/jjhe369/p/5785845.html
總結(jié)
以上是生活随笔為你收集整理的Logstash 父子关系 配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++线性序列容器vector简单总结
- 下一篇: UNIX标准及实现