首页 > 解决方案 > FluentD 配置以索引弹性日志中的所有字段

问题描述

嗨,我有来自 springboot 微服务的以下日志。在弹性的时间戳、级别、记录器等所有以下字段上创建索引的内容。如何在流利的配置中实现这一点?尝试了以下,它没有工作

日志

timestamp:2020-04-27 09:37:56.996 level:INFO level_value:20000 thread:http-nio-8080-exec-2 logger:com.scb.nexus.service.phoenix.components.ApplicationEventListener context:default message:org.springframework.web.context.support.ServletRequestHandledEvent traceId:a122e51aa3d24d4a spanId:a122e51aa3d24d4a spanExportable:false X-Span-Export:false X-B3-SpanId:a122e51aa3d24d4a X-B3-TraceId:a122e51aa3d24d4a

流利的conf

 <match **>
      @type elasticsearch
      time_as_integer true
      include_timestamp true
      host host
      port 9200
      user userName
      password password
      scheme https
      ssl_verify false
      ssl_version TLSv1_2
      index_name testIndex
    </match>
    <filter **>
      @type parser
      key_name log
      reserve_data true
      <parse>
        @type json
      </parse>
    </filter>

标签: fluentd

解决方案


日志不是 JSON 格式,因此您不能使用 Json 解析器。您有以下选项来解决此问题

1- 使用此处描述的正则表达式解析器https://docs.fluentd.org/parser/regexp 2- 使用record_reformer插件并手动提取项目

例子:

 <match **>
    @type record_reformer
    tag parsed.${tag_suffix[2]}
    renew_record false
    enable_ruby true
    <record>
       timestamp ${record['log'].scan(/timestamp:(?<param>[^ ]+ [^ ]+)/).flatten.compact.sort.first}
       log_level ${record['log'].scan(/level:(?<param>[^ ]+)/).flatten.compact.sort.first}
       level_value ${record['log'].scan(/level_value:(?<param>[^ ]+)/).flatten.compact.sort.first}
   </record>
  </match>

 <match parsed.**>
  @type elasticsearch
  time_as_integer true
  include_timestamp true
  host host
  port 9200
  user userName
  password password
  scheme https
  ssl_verify false
  ssl_version TLSv1_2
  index_name testIndex
</match>


推荐阅读