[英]Filebeat and LogStash — data in multiple different formats
我有 Filebeat、Logstash、ElasticSearch 和 Kibana。 Filebeat 位於單獨的服務器上,它應該接收不同格式的數據:syslog、json、來自數據庫等,並將其發送到 Logstash。
我知道如何設置 Logstash 以使其處理單一格式,但由於有多種數據格式,我將如何配置 Logstash 以正確處理每種數據格式?
事實上,我如何設置它們,Logstash 和 Filebeat,以便所有不同格式的數據都從 Filebeat 發送並正確提交到 Logstash? 我的意思是,處理發送和接收數據的配置設置。
要在 Logstash 管道中分離不同類型的輸入,請使用type
字段和tags
進行更多標識。
在您的 Filebeat 配置中,您應該為每種不同的數據格式使用不同的探礦者,然后可以將每個探礦者設置為具有不同的document_type:
字段。
例如:
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
語句對不同類型進行不同處理。
例如:
filter {
if [type] == "apache" {
# apache specific processing
}
else if [type] == "log_message" {
# log_message processing
}
}
如果您問題中的“數據格式”是編解碼器,則必須在logstash 的輸入中進行配置。 以下是關於 filebeat 1.x 和 logstash 2.x,而不是 elastic 5 堆棧。 在我們的設置中,我們有兩個節拍輸入 - 第一個是 default = "plain":
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 / lumberjack,您需要更多的端口。
7.5.1 支持
filebeat-multifile.yml // 安裝在機器上的文件beat
filebeat.inputs:
- type: log
tags: ["gunicorn"]
paths:
- "/home/hduser/Data/gunicorn-100.log"
- type: log
tags: ["apache"]
paths:
- "/home/hduser/Data/apache-access-100.log"
output.logstash:
hosts: ["0.0.0.0:5044"] // target logstash IP
gunicorn-apache-log.conf // 安裝在另一台機器上的日志存儲
input {
beats {
port => "5044"
host => "0.0.0.0"
}
}
filter {
if "gunicorn" in [tags] {
grok {
match => { "message" => "%{USERNAME:u1} %{USERNAME:u2} \[%{HTTPDATE:http_date}\] \"%{DATA:http_verb} %{URIPATHPARAM:api} %{DATA:http_version}\" %{NUMBER:status_code} %{NUMBER:byte} \"%{DATA:external_api}\" \"%{GREEDYDATA:android_client}\"" }
remove_field => "message"
}
}
else if "apache" in [tags] {
grok {
match => { "message" => "%{IPORHOST:client_ip} %{DATA:u1} %{DATA:u2} \[%{HTTPDATE:http_date}\] \"%{WORD:http_method} %{URIPATHPARAM:api} %{DATA:http_version}\" %{NUMBER:status_code} %{NUMBER:byte} \"%{DATA:external_api}\" \"%{GREEDYDATA:gd}\" \"%{DATA:u3}\""}
remove_field => "message"
}
}
}
output {
if "gunicorn" in [tags]{
stdout { codec => rubydebug }
elasticsearch {
hosts => [...]
index => "gunicorn-index"
}
}
else if "apache" in [tags]{
stdout { codec => rubydebug }
elasticsearch {
hosts => [...]
index => "apache-index"
}
}
}
從二進制運行 filebeat 給文件適當的權限
sudo chown root:root filebeat-multifile.yml
sudo chmod go-w filebeat-multifile.yml
sudo ./filebeat -e -c filebeat-multifile-1.yml -d "publish"
從二進制運行 logstash
./bin/logstash -f gunicorn-apache-log.conf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.