前言
之前我们介绍过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</ |