我使用Fluentd将两种类型的日志传送到Elasticsearch集群(应用程序和其他日志)。
日志位于相同的文件夹/var/log/containers/中,并且具有相同的名称格式,例如: app-randomtext.log、dts-randomtext.log等。
我想为它们分配不同的索引,以便将应用程序日志与此文件夹中现在或将来出现的任何其他应用程序日志分开。
下面是我在代码块中为"path“设置一个通配符的尝试,但它不起作用。谁能告诉我我的错误在哪里?谢谢
##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-随机文本.log中遵循尾部
谢谢
发布于 2019-08-24 04:01:59
最后我终于找到了答案。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>在这里,除了以app开头的那些文件之外,Fluentd遵循所有的*.log文件
https://stackoverflow.com/questions/57515902
复制相似问题