【问题标题】:Logging with Fluentd - why is the output of json log file appearing as textpayload (not jsonpayload)?使用 Fluentd 进行日志记录 - 为什么 json 日志文件的输出显示为 textpayload(不是 jsonpayload)?
【发布时间】:2017-10-23 16:41:38
【问题描述】:

我是 Fluentd 的新手。我在 GKE 中使用 stackdriver,并在 GKE 中自定义 Fluentd 配置以对日志进行一些更改。

在我的容器日志配置文件中:

<source>
  type tail
  format json
  time_key time
  path /var/log/containers/*.log
  pos_file /var/log/gcp-containers.log.pos
  time_format %Y-%m-%dT%H:%M:%S.%N%Z
  tag reform.*
  read_from_head true
</source>

某些容器的日志是 json 对象,但我看到它们的输出为 textpayload(当我在 GKE 上启用内置 Fluentd 时,它们显示为 jsonpayload)。

我不明白是什么原因造成的。 我会很感激任何建议。

【问题讨论】:

    标签: json logging fluentd stackdriver google-kubernetes-engine


    【解决方案1】:

    我不确定这个答案是否会涵盖您的案例,但它可能会为像我这样的人节省几个小时的调查时间。

    虽然 format 参数现在是 deprecated 并替换为 <parse>, 它确实支持json解析。

    这里的关键是 JSON 对象 structure
    第一个 nginx 访问日志示例,我已经 found do NOT work 与 Stackdriver 没有修改:

    log_format json_combined escape=json '{ "time_local": "$time_local", '
     '"remote_addr": "$remote_addr", '
     '"remote_user": "$remote_user", '
     '"request": "$request", '
     '"status": "$status", '
     '"body_bytes_sent": "$body_bytes_sent", '
     '"request_time": "$request_time", '
     '"http_referrer": "$http_referer", '
     '"http_user_agent": "$http_user_agent" }';
    

    这不起作用,因为 JSON 是单级的,而 Stackdriver 要求它在单个键下至少嵌套一次。 (至少在这个例子中使用了 fluentd 代理,其他情况不确定)

    这可以是下面 WORKING 示例 中的任何键,例如 accessLog

    log_format json_combined escape=json '{ "accessLog": { "time_local": "$time_local", '
     '"remote_addr": "$remote_addr", '
     '"remote_user": "$remote_user", '
     '"request": "$request", '
     '"status": "$status", '
     '"body_bytes_sent": "$body_bytes_sent", '
     '"request_time": "$request_time", '
     '"http_referrer": "$http_referer", '
     '"http_user_agent": "$http_user_agent" } }';
    

    如果在第一个 JSON 级别上使用 httpRequest,请注意它有 different purpose

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多