使用两个配置文件时的 Logstash 混合输出

Logstash mix output when using two config files

我在 Ubuntu 中使用 logstash 1.5.6。

我在 /etc/logstash/conf.d 中写了两个配置文件,指定了不同的 input/output 位置:

文件A:

input {
  file {
    type => "api"
    path => "/mnt/logs/api_log_access.log"
  }
}
filter {
  ...
}
output {
  if "_grokparsefailure" not in [tags] {
      elasticsearch {
        host => "localhost"
        protocol => "http"
        index => "api-%{+YYYY.MM.dd}"
        template => "/opt/logstash/template/api_template.json"
        template_overwrite => true
      }
  }
}

文件 B:

input {
  file {
    type => "mis"
    path => "/mnt/logs/mis_log_access.log"
  }
}
filter {
  ...
}
output {
  if "_grokparsefailure" not in [tags] {
      elasticsearch {
        host => "localhost"
        protocol => "http"
        index => "mis-%{+YYYY.MM.dd}"
        template => "/opt/logstash/template/mis_template.json"
        template_overwrite => true
      }
  }
}

但是,我可以看到来自 /mnt/logs/mis_log_access.log/mnt/logs/nginx/dmt_access.log 的数据都显示在索引 api-%{+YYYY.MM.dd}mis-%{+YYYY.MM.dd} 中,这不是我想要的。

配置有什么问题?谢谢。

Logstash 读取配置目录中的所有文件并将它们全部合并到一个配置中。

要为一种类型的输入仅制作一个过滤器或输出部分 运行,请使用条件:

if [type] == "api" {
   ....
}

它能更好地处理输入类型为

的过滤器

文件A:

input {
   file {
     type => "api"
     path => "/mnt/logs/api_log_access.log"
     }
 }

   if [type] == "api" {
     filter {
      ...
     }
   }

文件 B:

input {
 file {
    type => "mis"
    path => "/mnt/logs/mis_log_access.log"
  }
 }

   if [type] == "mis" {
     filter {
      ...
     }
   }

文件 C: output.conf

output {
  elasticsearch {
  hosts => ["localhost:9200"]
  index => "%{type}-%{+YYYY.MM.dd}"
  }
}

使用 logstash 5.1