Filebeat和LogStash - 多种不同格式的数据

时间:2016-06-07 16:02:24

标签: json elasticsearch logstash elastic-stack filebeat

我有Filebeat,Logstash,ElasticSearch和Kibana。 Filebeat位于一个单独的服务器上,它应该接收不同格式的数据:syslog,json,数据库等,并将其发送到Logstash。

我知道如何设置Logstash以使其处理单一格式,但由于有多种数据格式,我如何配置Logstash以正确处理每种数据格式?

实际上,我如何设置它们Logstash和Filebeat,以便从Filebeat发送不同格式的所有数据并正确地提交给Logstash?我的意思是,处理发送和接收数据的配置设置。

2 个答案:

答案 0 :(得分:4)

要在Logstash管道中分隔不同类型的输入,请使用type字段和tags进行更多识别。

在Filebeat配置中,您应该为每种不同的数据格式使用不同的prospector,然后可以将每个prospector设置为具有不同的document_type:字段。

Reference

例如:

filebeat:
  # List of prospectors to fetch data.
  prospectors:
    # Each - is a prospector. Below are the prospector specific configurations
    -
      # Paths that should be crawled and fetched. Glob based paths.
      # For each file found under this path, a harvester is started.
      paths:
        - "/var/log/apache/httpd-*.log"
      # Type to be published in the 'type' field. For Elasticsearch output,
      # the type defines the document type these entries should be stored
      # in. Default: log
      document_type: apache
    -
      paths:
        - /var/log/messages
        - "/var/log/*.log"
      document_type: log_message

在上面的示例中,来自/var/log/apache/httpd-*.log的日志将包含document_type: apache,而另一个探索者的日志则为document_type: log_message

当Logstash处理事件时,此document-type字段将成为type字段。然后,您可以在Logstash中使用if语句对不同类型执行不同的处理。

Reference

例如:

filter {
  if [type] == "apache" {
    # apache specific processing
  }
  else if [type] == "log_message" {
    # log_message processing
  }
}

答案 1 :(得分:1)

如果您问题中的“数据格式”是编解码器,则必须在logstash的输入中进行配置。以下是关于filebeat 1.x和logstash 2.x,而不是弹性5堆栈。 在我们的设置中,我们有两个节拍输入 - 第一个是默认=“普通”:

beats {
    port                => 5043
}
beats {
    port                => 5044
    codec               => "json"
}

在filebeat端,我们需要两个filebeat实例,将其输出发送到各自的端​​口。不可能告诉filebeat“将此prospector路由到该输出”。

文档logstash:https://www.elastic.co/guide/en/logstash/2.4/plugins-inputs-beats.html

备注:如果您使用不同的协议,例如遗留的logstash-forwarder / lumberjack,你需要更多的端口。