fluentd - Fluentd 日志源
问题描述
我正在使用 Fluentd 将两种类型的日志发送到 Elasticsearch 集群(应用程序和其他日志)。
位于同一文件夹 /var/log/containers/ 并具有相同名称格式的日志,例如:app-randomtext.log、dts-randomtext.log 等。
我想为它们分配不同的索引,以将应用程序日志与现在或将出现在此文件夹中的任何其他日志分开。
这是我尝试为块中的“路径”创建通配符,但它不起作用。谁能指出我的错误在哪里?谢谢
##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
推荐阅读
- android - 如何在android中制作通知声音列表?
- nim-lang - Nim:从过程返回表
- strapi - 如何在 Strapi 中处理自定义数据创建
- php - 在注册表单中添加的额外字段将保存在 wp_users 表中,而不是 wp_usermeta 表(WooCommerce)
- r - 如何在 R 中正确使用 read.table 与该数据库?
- typescript - 如何传递嵌套类以输入@ApiOkResponse 或创建适当的自定义装饰器?
- sql - 为什么不能删除角色,因为某些对象依赖于它
- python - 为什么 send_keys() 方法不起作用。`元素不可交互`
- python - Python - 将特定文件从子文件夹复制到目标,从文本文件中获取文件名
- android - NestedScrolling 不适用于 gridView