【问题标题】:fluentd JSON log field not being parsed流利的 JSON 日志字段未被解析
【发布时间】:2020-06-23 14:11:04
【问题描述】:

我正在关注https://docs.fluentd.org/container-deployment/docker-logging-driver 上的fluentd 教程

但我无法使 JSON 解析器工作。

我正在流畅地运行如下:

# ./demo.conf
<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<match *>
  @type stdout
</match>

<filter docker.**>
  @type parser
  key_name log
  reserve_data true
  <parse>
    @type json # apache2, nginx, etc...
  </parse>
</filter>
docker run -it -p 24224:24224 -v $(pwd)/demo.conf:/fluentd/etc/demo.conf -e FLUENTD_CONF=demo.conf fluent/fluentd:v1.3.2

我正在使用以下 docker run 命令将 JSON 日志模拟到 fluentd

docker run --log-driver=fluentd ubuntu echo '{"test":"test"}'
Expected: 2020-06-23 13:52:31.000000000 +0000 e54806b99130: {"log":"{\"test\":\"test\"}","container_id":"e54806b9913010d5ecb79b305d227db9e706299ad94bd070be6042dce735ed3b","container_name":"/wizardly_kalam","source":"stdout","test":"test"}
Actual:   2020-06-23 13:52:31.000000000 +0000 e54806b99130: {"log":"{\"test\":\"test\"}","container_id":"e54806b9913010d5ecb79b305d227db9e706299ad94bd070be6042dce735ed3b","container_name":"/wizardly_kalam","source":"stdout"}

根据reserve_data 文档,它应该可以工作,但我无法理解问题所在。

【问题讨论】:

    标签: docker fluentd


    【解决方案1】:

    也许我遗漏了一些东西,但 Fluentd 不尊重配置中的步骤顺序吗?在解析字段之前打印到标准输出。试试这个:

    # ./demo.conf
    <source>
      @type forward
      port 24224
      bind 0.0.0.0
    </source>
    
    <filter docker.**>
      @type parser
      key_name log
      reserve_data true
      <parse>
        @type json # apache2, nginx, etc...
      </parse>
    </filter>
    
    <match *>
      @type stdout
    </match>
    

    【讨论】:

    • 我的错,答案是正确的。我刚刚也遇到了 docker --log-opt 标签的另一个问题。
    猜你喜欢
    • 2021-07-31
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 2020-08-07
    • 2020-10-08
    相关资源
    最近更新 更多