【问题标题】:Extracting fields from paths in logstash从logstash中的路径中提取字段
【发布时间】:2014-05-10 02:18:47
【问题描述】:

我正在配置 logstash 以从多个主机上的多个工作人员收集日志。我目前正在为主机添加字段:

input {
    file {
            path => "/data/logs/box-1/worker-*.log"
            add_field => {
                "original_host" => "box-1" 
            }
    }
    file {
            path => "/data/logs/box-2/worker-*.log"
            add_field => {
                "original_host" => "box-2"
            }
    }

但是,我还想添加一个字段{'worker': 'A'} 等等。我有很多工人,所以我不想为主机和工人的每个组合写一个file { ... } 块。

我还有其他选择吗?

【问题讨论】:

    标签: logstash


    【解决方案1】:

    你应该可以做一个path => "/data/logs/*/worker-*.log" 然后添加一个 grok 过滤器来提取你需要的东西。

    filter { grok { match => [ "path", "/(?<original_host>[^/]+)/worker-(?<worker>.*).log" ] } }

    或非常接近的东西.... 可能想用if [path] =~ /worker/ 包围它,这取决于您的配置文件中还有什么。

    【讨论】:

    • 巧妙!谢谢你:)
    猜你喜欢
    • 2014-07-26
    • 2020-12-09
    • 2014-03-26
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 2013-02-20
    相关资源
    最近更新 更多