【问题标题】:Where do the time fields in my structured log messages come from?我的结构化日志消息中的时间字段来自哪里?
【发布时间】:2020-01-12 03:06:08
【问题描述】:

我正在将 json 结构化日志消息写入标准输出,其中只有一个时间字段,称为 origin_timestamp。

我使用 Fluent Bit 和尾部输入插件收集日志消息,该插件使用解析器 docker。解析器配置了Time_Key time。

关于Time_Key 的文档说:

如果日志条目提供带有时间戳的字段,则此选项 指定该字段的名称。

由于 time != origin_timestamp,我原以为 Fluent Bit 不会添加时间字段,但是最终在 Elasticsearch 中的日志消息具有以下时间字段:

  • (origin_timestamp 在包含原始日志消息的字段日志中)
  • origin_timestamp
  • time
  • @timestamp(有时甚至多次)。

@timestamp 字段可能是我在 Fluent Bit 中使用的 es 输出插件添加的,但是 time 字段到底是从哪里来的?

【问题讨论】:

    标签: docker elasticsearch logging kubernetes fluent-bit


    【解决方案1】:

    我在 Fluent-bit 问题跟踪器Duplicate @timestamp fields in elasticsearch output 中遇到了以下问题,这听起来可能与您的问题有关。

    我已深度链接到其中一位贡献者的特定评论,其中概述了两种可能的解决方案,具体取决于您是使用他们的 Kubernetes 过滤器插件,还是直接将日志摄取到 Elasticsearch 中。

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回答(+1),这解释了时间戳字段,但我仍然不知道在哪里添加时间字段。
    【解决方案2】:

    docker json 插件添加的时间字段。 Docker 日志插件默认从您的标准输出中获取日志并记录到以下格式的文件中:

    {"log":"Log line is here\n","stream":"stdout","**time**":"2019-01-01T11:11:11.111111111Z"}
    

    因此,您可能会在最终日志中观察到三个时间戳:

    1. 由您添加(origin_timestamp)
    2. 由 docker 驱动程序添加(时间)
    3. 由 fluent bit 插件 (@timestamp) 添加

    参考 - https://docs.docker.com/config/containers/logging/json-file/

    【讨论】:

      猜你喜欢
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多