【问题标题】:How to parse redis log with fluentd如何使用fluentd解析redis日志
【发布时间】:2021-02-07 21:14:07
【问题描述】:

我想在 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日志?

【问题讨论】:

    标签: google-cloud-platform redis fluentd


    【解决方案1】:

    您的示例 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>
    

    【讨论】:

    • 感谢约翰·汉利!应用您的解析格式后,我在 gcp 上看到了 redis 日志!虽然我对你发布的格式还不熟悉,但我会尽力理解它!
    • @user389955 - 试试这个链接来测试format 正则表达式。此链接还将帮助您构建流利的配置。 fluentular.herokuapp.com
    猜你喜欢
    • 2019-10-20
    • 2022-08-22
    • 1970-01-01
    • 2017-05-18
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多