如何用fluentd解析redis日志

时间:2021-02-07 21:14:07

标签: google-cloud-platform redis fluentd

我想在 gcp 日志浏览器中显示 redis 日志。为此,我按照 https://www.fluentd.org 在具有 redis 日志的 gcp 实例上安装了 fluentd。然后我配置了td-agent.conf如下:

<source>
  @type tail
  format none
  path /var/log/redis/*.log
  pos_file /var/log/td-agent/pos/redis-server-log.pos
  read_from_head true
  <parse>
      @type syslog
  </parse>
  tag redis
</source>

<filter **>
  @type add_insert_ids
  insert_id_key uniq_id # Optional.
</filter>

<match **>
  @type google_cloud
</match>

/var/log/redis/redis.log 的格式为:

40165:M 28 Jan 2021 16:06:57.699 - 0 clients connected (0 replicas), 1449680 bytes in use
40165:M 28 Jan 2021 16:07:02.720 - 0 clients connected (0 replicas), 1449680 bytes in use
40165:M 28 Jan 2021 16:07:05.592 - Accepted 127.0.0.1:40696

不知何故,我在 gcp 日志记录中没有看到 redis 日志。我怀疑部分 td-agent.conf 不应该是 syslog。但是我应该使用什么解析器来解析 redis 日志?

1 个答案:

答案 0 :(得分:2)

您的示例 redis 日志没有格式。它是以日期字符串为前缀的非结构化文本。

检查您是否有日志轮换。如果是,那么您可能不想使用 *.log。而是指定日志文件名。

这就是我要使用的:

<source>
  @type tail

  # Parse the timestamp and collect the entire line as 'message'
  format /^(?<message>(?<time>[^ ]*\s*[^ ]* [^ ]*) .*)$/

  path /var/log/redis/*.log
  pos_file /var/lib/google-fluentd/pos/redis.log.pos
  read_from_head true
  tag redis
</source>