logstash入门系列(二)——简单运用

一、Hello World

     和绝大多数IT技术介绍一样,我们的以“Hello World”开始Logstash的运用。
  1、在终端用命令启动Logstash进程      
     [root@wn2 logstash-1.5.5]# bin/logstash -e 'input{stdin{}} output{stdout{codec => rubydebug}}'
     2、 终端等待用户输入,输入Hello World,回车
     
  3、结果
     

二、从控制台输入日志并解析

  1、日志内容       
      2017-04-19 20:35:41 JRebel: A newer version '7.0.7' is available for download 
   2、命令  
     [root@wn2 logstash-1.5.5]# bin/logstash -e 
      'input{ 
           stdin{}
       } 
       filter{
           grok{
               match=>["message","%{DATE:date}\s%{TIME:time}"]
           }
       } 
       output{
           stdout{
               codec => rubydebug
           }
       }'
   3、输出结果                                                                                      

三、从文件输入并解析

   1、新建文件Logstash.conf
      命令:vi Logstash.conf
      文件内容:       
       input {
	   file {
               path => "/tmp/access.log"                      //日志文件的位置   
               start_position => "beginning"             
           }     
       }

       filter{
	   grok{
               match=>["message","%{DATE:date}\s%{TIME:time}"]
           }
       }

       output{
           stdout{
               codec=>rubydebug
           }
       }
   2、命令
                   bin/logstash -f Logstash.conf
   3、结果
      同2.3

四、输入日志为多行

    1、日志内容(共7条日志)
[16-04-12 03:40:01 DEBUG] model.MappingNode:- ['/store/shopclass'] matched over.
[16-04-12 03:40:02 DEBUG] impl.JdbcEntityInserter:- from product_category product_category
where product_category.PARENT_ID is null and product_category.STATUS = ? and product_category.DEALER_ID is null
order by product_category.ORDERS asc
[16-04-12 03:40:03 DEBUG] model.MappingNode:- ['/store/shopclass'] matched over.
[16-04-12 03:40:04 DEBUG] model.MappingNode:- ['/store/shopclass'] matched over.
[16-04-12 03:40:05 DEBUG] impl.JdbcEntityInserter:- from product_category product_category
where product_category.PARENT_ID is null and product_category.STATUS = ? and product_category.DEALER_ID is null
order by product_category.ORDERS desc
[16-04-12 03:40:06 DEBUG] impl.JdbcEntityInserter:- from product_category product_category
where product_category.PARENT_ID is null and product_category.STATUS = ? and product_category.DEALER_ID is null
order by product_category.ORDERS asc
[16-04-12 03:40:07 DEBUG] model.MappingNode:- ['/store/shopclass'] matched over.
2、命令       




        input {
            file{
                path=>"/tmp/access_log"                
                codec=> multiline {
                            pattern => "^\["
                            negate => true
                            what => "previous"
                        }                
           }
        }
        output{
            stdout{
                codec=>rubydebug
            }
        }
    3、结果
       只解析到了6条日志,这个插件的原理是把当前行的数据添加到前面一行后面,直到新进的当前行匹配
       ^\[正则为止。因为最后的输入并不匹配设定的正则表达式,logstash还得等下一行数据直到匹配成功后才        会输出这个事件。
    4、使用logstash-filter-multiline插件
       ①、命令
           
   
       

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值