2016-06-07 26 views
1

我有Filebeat,Logstash,ElasticSearch和Kibana。 Filebeat位于单独的服务器上,它应该以不同的格式接收数据:syslog,json,从数据库等发送到Logstash。Filebeat和LogStash - 多种不同格式的数据

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

事实上,我怎样才能设置它们两个,Logstash和Filebeat,以便所有不同格式的数据都从Filebeat发送并正确提交给Logstash?我的意思是,处理发送和接收数据的配置设置。

回答

5

要在Logstash流水线中分离不同类型的输入,请使用type字段和tags以获取更多标识。

在您的Filebeat配置中,您应该为每种不同的数据格式使用不同的探勘器,然后可以将每个探矿者设置为具有不同的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 
    } 
} 
+0

好的,但如果系统日志格式和其他人在json中的某些消息?我应该在logstash的“输出”中指定哪个“编解码器”? –

+0

我的意思是,那些来自filebeat到logstash的。 –

+0

编解码器不是logstash elasticsearch输出中的必需设置 –

1

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

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

在filebeat方面,我们需要两个filebeat情况下,将自己的输出到它们各自的端口。这是不可能告诉filebeat“路线这个探矿者到那个输出”。

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

备注:如果您附带不同的协议,例如传统的logstash-forwarder /伐木工人,你需要更多的端口。

相关问题