k8s与log--利用lua为fluent bit添加一个filter

本文介绍了如何利用Lua语言为Fluent Bit创建自定义filter,以满足从日志record中提取特定字段的需求。通过遵循官方的lua编写filter规范,实现了从source字段提取appname和filename的功能。在K8s环境中,将lua脚本集成到Fluent Bit镜像中,并提供了使用示例。虽然Fluent Bit的相关资料有限且调试困难,但通过Lua编写filter提供了一种解决问题的思路。
摘要由CSDN通过智能技术生成

前言

之前我们介绍过fluent bit这个日志收集神器。最近我们遇到奇葩的需求,不得不利用lua编写fluent bit的filter,来满足需求。

首先介绍一下需求:
非容器的日志团队使用filebeat, 其配置文件部分如下:

processors:
- dissect:
    tokenizer: "/data/logs/%{appname}/%{filename}.log"
    field: "source"
    target_prefix: ""

即需要从日志record的source filed 提取appname和filename两个filed。

fluent bit 并没有如此的插件,所以不得不自己实现。

实现

lua编写filter规范

官方给出的示例如下:

function cb_print(tag, timestamp, record)
   return code, timestamp, record
end

Function 输入参数

Function Arguments
name description
tag Name of the tag associated with the incoming record.
timestamp Unix timestamp with nanoseconds associated with the incoming record. The original format is a double (seconds.nanoseconds)
record Lua table with the record content
Return Values

Each callback must return three values:

name data type description
code integer</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值