首页 > 解决方案 > 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 的尾部

谢谢

标签: fluentd

解决方案


最后我设法找到了答案。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


推荐阅读