码迷,mamicode.com
首页 > 其他好文 > 详细

ELK 学习笔记之 Logstash之filter配置

时间:2017-09-23 21:30:57      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:alt   一个   position   学习笔记   c99   sage   正则表达式   osi   style   

Logstash之filter:

 

json filter:

input{

       stdin{

       }

}

filter{

       json{

              source => "message"

       }

}

output{

       stdout{

              codec => json

       }

输入:

{"name": "CSL", "age": 20}

输出:

技术分享

 

Grok filter:

pattern: 

https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns

创建一个测试log:

[sky@hadoop1 bin]$ cat spark-test-log.log

05/30/17 17:13:24 INFO StartingSparkmasteratspark

05/30/17 17:13:24 INFO RunningSparkversion1

05/30/17 17:13:25 INFO jetty

 

创建conf:

input{

       file{

              path => "/usr/local/logstash-5.6.1/bin/spark-test-log.log"

              type => "sparkfile"

              start_position => "beginning"

       }

}

filter{

       grok{

              match => ["message", "%{DATE:date} %{TIME:time} %{LOGLEVEL:loglevel} %{WORD:word}"]

       }

}

output{

       stdout{

              codec => rubydebug

       }

}

运行结果:

技术分享

自定义正则表达式:

[sky@hadoop1 patterns]$ cat selfpattern

SKYTIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9])

 

修改conf:

input{

       file{

              path => "/usr/local/logstash-5.6.1/bin/spark-test-log.log"

              type => "sparkfile"

              start_position => "beginning"

       }

}

filter{

       grok{

              patterns_dir => ‘/usr/local/logstash-5.6.1/patterns/selfpattern‘

              match => ["message", "%{DATE:date} %{SKYTIME:time} %{LOGLEVEL:loglevel} %{WORD:word}"]

       }

}

output{

       stdout{

              codec => rubydebug

       }

}

输出结果:

技术分享

 

定义多个match:使用,分隔。

测试正则表达式网址:

https://grokdebug.herokuapp.com/

 

ELK 学习笔记之 Logstash之filter配置

标签:alt   一个   position   学习笔记   c99   sage   正则表达式   osi   style   

原文地址:http://www.cnblogs.com/AK47Sonic/p/7582283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!