预处理包含多个日志记录的消息

Preprocessing a message containing multiple log records

TL;DR。是否可以通过在换行符上拆分来预处理消息,然后让每条消息像往常一样通过 fluentd 管道?

我正在用 fluentd 接收这些日志消息:

2018-09-13 13:00:41.251048191 +0000 : {"message":"146 <190>1 2018-09-13T13:00:40.685591+00:00 host app web.1 - 13:00:40.685 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Received GET /alerts\n"}
2018-09-13 13:00:41.337628343 +0000 : {"message":"199 <190>1 2018-09-13T13:00:40.872670+00:00 host app web.1 - 13:00:40.871 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Processing with Api.AlertController.index/2 Pipelines: [:api]\n156 <190>1 2018-09-13T13:00:40.898316+00:00 host app web.1 - 13:00:40.894 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Rendered \"index.json\" in 1.0ms\n155 <190>1 2018-09-13T13:00:40.898415+00:00 host app web.1 - 13:00:40.894 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Sent 200 response in 209.70ms\n"}

这些日志的问题在于第二条消息:它包含多个应用程序日志行。

不幸的是,这是我必须处理的:系统(你好,Heroku 日志!)我正在使用缓冲区日志并将它们作为一个块吐出,因此无法知道数字块中预先记录的记录数。

这是 Heroku 日志排空的 known property

有没有办法对日志消息进行预处理,以便我得到一个平坦的消息流,以便后续的 fluentd 设施正常处理?

post 处理后的消息流应该是这样的:

2018-09-13 13:00:41.251048191 +0000 : {"message":"146 <190>1 2018-09-13T13:00:40.685591+00:00 host app web.1 - 13:00:40.685 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Received GET /alerts\n"}
2018-09-13 13:00:41.337628343 +0000 : {"message":"199 <190>1 2018-09-13T13:00:40.872670+00:00 host app web.1 - 13:00:40.871 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Processing with Api.AlertController.index/2 Pipelines: [:api]\n"}
2018-09-13 13:00:41.337628343 +0000 : {"message":"156 <190>1 2018-09-13T13:00:40.898316+00:00 host app web.1 - 13:00:40.894 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Rendered \"index.json\" in 1.0ms\n"}
2018-09-13 13:00:41.337628343 +0000 : {"message":"155 <190>1 2018-09-13T13:00:40.898415+00:00 host app web.1 - 13:00:40.894 request_id=40932fe8-cd7e-42e9-af24-13350159376d [info] Sent 200 response in 209.70ms\n"}

P.S。我当前的配置非常基础,但我 post 正在使用它以防万一。我想做的就是了解原则上是否有可能对消息进行预处理?

<source>
  @type http
  port 5140
  bind 0.0.0.0

  <parse>
    @type none
  </parse>
</source>

<filter **>
  @type stdout
</filter>

https://github.com/hakobera/fluent-plugin-heroku-syslog怎么样?

fluent-plugin-heroku-syslog 自 4 年前以来一直没有维护,但它将使用兼容层与 Fluentd v1 一起工作。