首页 > 解决方案 > 如何在 logstash conf 文件中使用包含?

问题描述

可以在 logstash 配置文件中使用包含吗?

最小、完整和可验证的示例

这个可以换吗...

文件:beats.conf

input {
  beats {
    port => 5044
  }
}
filter {
    date {
        match => ["myTimestamp", "yyyyMMdd_HH:mm:ss.SSS"]
        target => "date_time"
    }
}
output {
  elasticsearch {
    hosts => [ "localhost:9200" ]
  }
}

...有了这个?

文件:date.inc

date {
    match => ["myTimestamp", "yyyyMMdd_HH:mm:ss.SSS"]
    target => "date_time"
}

文件:beats.conf

input {
  beats {
    port => 5044
  }
}
filter {
    #include <date.inc>  // <- THIS THIS THIS THIS THIS
}
output {
  elasticsearch {
    hosts => [ "localhost:9200" ]
  }
}

标签: elasticsearchlogstashfilebeat

解决方案


实际上不支持“包含”,并且 Logstash 无法加载拆分为不同文件的管道以重用公共部分。 编辑:从不同文件组成管道的唯一方法是在设置中指定文件夹或通配符“*”,path.config以便按字母顺序读取配置文件(感谢@Badger)。

如果您不想定义自己的管道的组合/编译系统,您可以查看“管道到管道”通信,该通信可用于分解复杂的管道并在不同的流上重用过滤器:https ://www.elastic.co/guide/en/logstash/current/pipeline-to-pipeline.html 。请注意,使用这种方法,您将支付运行多个管道的开销。

例如:

管道.yml

- pipeline.id: input
  path.config: "<path-to-file>/beats.conf"
- pipeline.id: date-filters
  # This common pipeline allow to reuse the same logic for complex filters
  path.config: "<path-to-file>/date.conf"
- pipeline.id: output
  path.config: "<path-to-file>/elasticsearch.conf"

beats.conf

input {
  beats {
    port => 5044
  }
}
output { pipeline { send_to => [commonFilters] } }

日期.conf

input { pipeline { address => commonFilters } }
filter {
  date {
    match => ["myTimestamp", "yyyyMMdd_HH:mm:ss.SSS"]
    target => "date_time"
  }
}
output { pipeline { send_to => [output] } }

弹性搜索.conf

input { pipeline { address => output } }
output {
  elasticsearch {
    hosts => [ "localhost:9200" ]
  }
}

推荐阅读