从logstash中的路径提取字段

从logstash中的路径提取字段,logstash,Logstash,我正在配置logstash以从多台主机上的多个工作进程收集日志。我当前正在为主机添加字段: input { file { path => "/data/logs/box-1/worker-*.log" add_field => { "original_host" => "box-1" } } file { path =>

我正在配置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'}
等等。我有很多worker,所以我不想为主机和worker的每个组合编写
文件{…}


我有其他选择吗?

您应该能够执行一个
路径=>“/data/logs/*/worker-*.log”
然后添加一个grok筛选器以提取您需要的内容

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


或者与之非常接近的东西。。。。如果[path]=~/worker/取决于配置文件中的其他内容,则可能需要将其包围起来。

巧妙!谢谢:)