Promtail:时间戳未正确解析为 Loki 和 Grafana

问题描述

目前,我希望处理 json 格式的日志。

我已设法将给定的时间戳转换为 RFC3339 格式。但是通过Promtail解析的时候,好像解析了但是没有作为显示的时间戳。相反,它使用 Promtail 将所述日志推送到 Loki 的时间戳。

以下是我的 Promtail 配置片段:

scrape_configs:
- job_name: Test
  static_configs:
  - targets:
      - localhost
    labels:
      job: Testing2
      __path__: /path/to/*.json

  pipeline_stages:
  - json:
      expressions:
        timestamp: timestamp
  - timestamp:
      source: timestamp
      format: 2006-01-02T15:04:05Z07:00

我也尝试将时间戳格式切换为 RFC3339 也没有结果。

下面是我生成的示例日志

{"id":5072,"type":0,"timestamp":"2021-06-28T03:00:05+08:00","user":"System","ip":"127.0.0.1","computer":"localhost","desc":"Dummy message"}

这就是日志在 Grafana 中的显示方式。时间戳字段和 ts 字段(用于在 Grafana 中显示)是不同的。

Sample Log as shown in Grafana

对于调试的任何帮助或指导,我将不胜感激。如果需要任何其他信息,请告诉我!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)