Logstash 读取tomcat错误日志

Logstash 读取tomcat错误日志

概述

最近搭建了elk日志分析系统、想读取一下tomcat的错误日志、但是一个异常由于换行总是分多次存储展示、导致不是很清晰的看一个错误日志信息

  • inputs 输入
  • codecs 解码
  • filters 过滤
  • outputs 输出

image image image

例子

安装插件 logstash-filter-multiline

在线安装插件

logstash-plugin.bat install logstash-filter-multiline

升级插件 
logstash-plugin.bat update logstash-filter-multiline

离线安装
logstash-plugin.bat install logstash-filter-multiline.gem

卸载
logstash-plugin.bat uninstall logstash-filter-multiline

例子

如果不是以 “[“开头的日志 都跟上一个日志合并在一起。以此类推遇到其他的多行日志也可以按照这个方法来做合并。

input {  
    file { 
		type => "tomcat_error"
        path => "E:/install/temp/*.log"
		start_position => beginning
    }  
} 

filter {
    if [type] == "tomcat_error" {
            multiline {
                      pattern => "^[^\[]"
                      what => "previous"
                  }
                mutate {
           split => ["message", "|"]
        }
        grok {
            match => { 
                           "message" => "(?m)%{TIMESTAMP_ISO8601:logtime}"
            }
        }
    }
}
 

output {    
    elasticsearch { hosts => localhost   
                    index => "logstash-cmis"  
                    document_type =>"tomcat"}  
      
    stdout { codec => rubydebug  }   
}  

例子一

input {  
    file {  
        path => "E:/install/temp/*.log"
		start_position => beginning
    }  
} 
 

output {    
    elasticsearch { hosts => localhost   
                    index => "logstash-cmis"  
                    document_type =>"tomcat"}  
      
    stdout { codec => json_lines }   
}  

例子二


input {  
    file {  
        path => "E:/install/temp/*.log"
		start_position => beginning
        codec => multiline {  
            pattern => "^\s"  
            what => "previous"  
        }  
    }  
} 

 filter {  
    multiline {    
		pattern => "^\s+%{TIMESTAMP_ISO8601}"  
		negate=>true    
		what=>"previous"    
	}

}

output {    
    elasticsearch { hosts => localhost   
                    index => "logstash-cmis"  
                    document_type =>"tomcat"}  
      
    stdout { codec => json_lines }   
}  

例子

input {  
    file{  
        path => "E:/install/temp/*.csv"  
        start_position => beginning  
    }  
 }    
    
filter {  
    grok {  
        patterns_dir => "patterns.txt"  
        match =>{ "message" => "%{DATA:name},%{DATA:person_id},%{DATA:email},%{DATA:tel},%{DATA:adress},%{DATA:from}%{S}" }  
        }  
    mutate{  
        remove_field => ["host","path","message","@version"]  
}  
}  
    
output {    
    elasticsearch { hosts => localhost   
                    index => "sgdb"  
                    document_type =>"sgdb"}  
      
    stdout { codec => rubydebug }   
}  

例子四

  • 分割匹配日志

日志格式

2015-09-28·09:50:48·[http-bio-80-exec-13]·DEBUG·com.weitoo.server.aspect.LogAspect·-{ip:183.16.4.40,url:http://api.xx.com/server/sc/commodity/getOnlineCommodity,param:{"shopId":1000001,"needCategory":false,"needCommodityTotal":false,"searchCommodityId":1002001},return:{"status":1},cost:3.911ms}
SERVER_LOG %{DATA:year}-%{DATA:month}-%{DATA:day}\ %{DATA:hour}\:%{DATA:min}\:%{DATA:sec}\ %{DATA:level}\ %{DATA:class} -{ip:%{DATA:ip},url:%{DATA:url},param:%{DATA:param},return:%{DATA:return},cost:%{BASE10NUM:cost}

conf

input {
  file {
   type=>"xx_server_log"
   path=>"/opt/software/apache-tomcat-7.0.59/logs/catalina.out"
   codec=> multiline {
           pattern => "(^.+Exception:.+)|(^\s+at .+)|(^\s+... \d+ more)|(^\s*Caused by:.+)"
           what=> "previous"
    }

 }
}



filter {
        if [type] == "xx_server_log" {
           grok {
                 match => [ "message","%{SERVER_LOG}"]
                 patterns_dir => ["/opt/conf/logstash"]
                 remove_field => ["message"]
          }
        }
}


output {
   elasticsearch {
  host =>"xx-management"
  protocol =>"http"
  workers => 5
  template_overwrite => true

}
   stdout { codec=> rubydebug }
}

清空es数据

DELETE /logstash-cmis

DELETE /.kibana/index-pattern/logstash-cmis

GET /_search
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值