fluentd - 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>
解决方案
日志不是 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>
推荐阅读
- python - 如何拆分数字值?
- javascript - React 中的 env-vars 使用 Dotenv 和 Webpack
- r - 如何用 R 中的一个 case_when 表达式改变两列?
- amazon-web-services - 在 Glue Dev Endpoint 上为 Sagemaker 设置 Spark 版本
- visualization - 如果不将度量转换为维度,如何在不聚合的情况下显示度量值?
- html - 在iOS11和Cordova上上传带有html文件类型输入的文件时选择文件失败
- github - 如果我更改我的 GitHub 用户名,我会丢失与我共享的私有存储库吗?
- typescript - Firestore删除对象中的字段是数组中另一个对象的字段
- networking - “ping -Mdo”不会禁止 MTU 低于 1500 的碎片
- react-native - 当 flexDirection 中的“列反向”时,React Native ScrollView 不起作用