logstash收集时filebeat区分日志

logstash收集时filebeat区分日志

 

1.场景

filebeat在服务器中同时收集nginx和web项目日志,需要对两个日志在logstash中分别处理

2.版本区别

==6.x之前==的可以使用filebeat的prospectors里面配置document_type类型,然后在logstash里面使用if [type] == “string” 来匹配,这里不做详细记录
==6.x之后==配置文件不支持document_type,也就是说旧方法是失效的,目前我使用的是==6.2.3==版本的filebeat

3.解决方法

在filebeat里面新增一个fields字段,对这个字段做记录然后在logstahs中进行区分

filebeat配置

filebeat.prospectors:

- type: log

  paths:
    - /Library/apache-tomcat-8.5.15/bin/logs/web.log
    #- c:\programdata\elasticsearch\logs\*

  fields: 
    document_type: weblog   #这一行的key:value都可以自己定义

logstash配置

output{
    if[fields][document_type] == "weblog" {
        stdout { codec => rubydebug }  
    }
}

猜你喜欢

转载自www.cnblogs.com/xiao-xue-di/p/11760377.html