我使用 Fluentd 将两种类型的日志传送到 Elasticsearch 集群(应用程序日志和其他日志)。
日志位于同一文件夹/var/log/containers/并具有相同的名称格式,例如:app-randomtext.log、dts-randomtext.log 等。
我想为它们分配不同的索引,以将应用程序日志与当前存在或将出现在此文件夹中的任何其他应用程序日志分开。
这是我尝试在 block 中为“路径”创建通配符,但它不起作用。有人能指出我的错误在哪里吗?谢谢
##source for app logs
<source>
@type tail
path /var/log/containers/app*.log
pos_file /var/log/fluentd-containers-app.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag app.*
keep_time_key true
format json
</source>
##source for everything else
<source>
@type tail
path /var/log/containers/!(app*.log)
pos_file /var/log/fluentd-containers-non-app.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag non-app.*
keep_time_key true
format json
</source>
<match app.**>
@type "aws-elasticsearch-service"
type_name "kube-fluentd-aws-es"
index_name app
include_tag_key true
tag_key "@log_name"
@log_level info
<endpoint>
url "#{ENV['ELASTICSEARCH_URL']}"
region "#{ENV['ELASTICSEARCH_REGION']}"
access_key_id "#{ENV['ELASTICSEARCH_ACCESS_KEY']}"
secret_access_key "#{ENV['ELASTICSEARCH_SECRET_KEY']}"
</endpoint>
</match>
<match non-app.**>
@type "aws-elasticsearch-service"
type_name "kube-fluentd-aws-es"
index_name non-app
include_tag_key true
tag_key "@log_name"
@log_level info
<endpoint>
url "#{ENV['ELASTICSEARCH_URL']}"
region "#{ENV['ELASTICSEARCH_REGION']}"
access_key_id "#{ENV['ELASTICSEARCH_ACCESS_KEY']}"
secret_access_key "#{ENV['ELASTICSEARCH_SECRET_KEY']}"
</endpoint>
</match>
我希望 Fluentd 跟踪文件夹中所有日志的尾部,但使用此配置 Fluentd 仅跟踪 app-randomtext.log 的尾部
谢谢
最佳答案
终于我找到了答案。 exclude_path
是我所需要的。
##source for everything else
<source>
@type tail
path /var/log/containers/*.log
exclude_path ["/var/log/containers/app*.log"]
pos_file /var/log/fluentd-containers-non-app.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag non-app.*
keep_time_key true
format json
</source>
此处 Fluentd 遵循所有 *.log
文件,不包括以 app
开头的文件
关于Fluentd日志源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57515902/