要在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
}
}
好的,但如果系统日志格式和其他人在json中的某些消息?我应该在logstash的“输出”中指定哪个“编解码器”? –
我的意思是,那些来自filebeat到logstash的。 –
编解码器不是logstash elasticsearch输出中的必需设置 –