带尾的多行单日志文件处理

问题描述

我有一个日志文件,该文件不断被附加到 括号中包含以下字段:

enter image description here

我计划使用Promtail将以下单个文件实时解析为 新记录将附加到该记录。

Promtail可能吗?我不确定它是否可以处理 多行处理。如果确实如此,那怎么办 期望吗?具有单个记录且持续不断的单个文件 用新信息覆盖?

解决方法

这是一个相当老的问题,但仍然:

是的,这是可能的。我在类似的场景中使用它。 该服务在文件末尾附加一个新行 (JSON),然后由 Promtail 处理。

promtail 配置如下所示:

scrape_configs:
- job_name: <name>
  pipeline_stages:
  - json:
      expressions:
        thread: thread
        level: level
        message: message
        timestamp: timestamp
        traceID: trace-id
        correlationID: correlation-id
  - labels:
      level:
  - template:
      source: new_key
      template: 'thread={{ .thread }} level={{ .level | ToLower }} correlationID={{ .correlationID }} traceID={{ .traceID }} | {{ .message }}'
  - output:
      source: new_key
  static_configs:
  - targets:
     - localhost
    labels:
      job: <some job name>
      __path__: /log/output.json

json 行(修饰)如下所示:

{"instant": {
"epochSecond": 1613470246,"nanoOfSecond": 779983000
},"thread": "thread-name","level": "WARN","loggerName": "it.issome.logger.class.name","message": "Some kind of message","endOfBatch": false,"loggerFqcn": "org.apache.logging.slf4j.Log4jLogger","threadId": 31,"threadPriority": 5,"correlation-id": "correlation-id","trace-id": "d6555df8asdf456a","timestamp": "2021-02-16T10:10:46.779+0000"
}

关于 promtail 的好材料和故障排除技巧并不多,或者我很难找到它:)