Fluentd日志源

标签 fluentd

我使用 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/

相关文章:

amazon-web-services - 如何为 VMWare 的 fluentd operator 安装 ConfigMap 卷?

logging - FluentD 日志不可读。它被排除在外,下次会检查

ubuntu - Fluentd、Elasticsearch 和 Kibana 设置

logging - Fluentd + golang 日志记录应用程序出错

json - Kubernetes 使用转义引号将 JSON 日志保存到文件中。为什么?

docker - 如何从非 root 用户监控 docker 容器日志?

ruby - 将数字日期转换为Fluentd中的字符串日期字段以存储到Elasticsearch中

带有 envsubst 和 tee 的 Docker CMD

java - 从 in_exec Fluentd 插件启动 java 命令

json - 修改 fluentd json 输出