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

时间:2015-12-29 02:09:38

标签: nginx elasticsearch logstash elastic-stack

我在Ubuntu中使用logstash 1.5.6。

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

档案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}中,这不是我想要的。

配置有什么问题?感谢。

2 个答案:

答案 0 :(得分:2)

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

要使一个过滤器或输出部分仅针对一种输入运行,请使用条件:

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

答案 1 :(得分:1)

最好处理输入类型为

的过滤器

档案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