FluentBit-从Path_Key进行解析 [英] FluentBit - Parsing from Path_Key
问题描述
当前,我使用Path_Key添加文件路径.我正在尝试获取Path_key中存在的多个变量.
Currently im adding the filepath using Path_Key. I am trying to grab multiple variables that exist in the Path_key.
/var/log/containers/**Application_Name**-**Application_Version**.log
是否可以从现有的字段映射中提取这些值?
Is it possible to extract these values from an existing field mapping?
推荐答案
要提取要在 Tag
中使用的值,这很简单,您可以输入以下内容:
For extracting values for use in the Tag
it is pretty straight forward, you would have an input like:
[INPUT]
Name tail
Path /var/log/containers/*-*.log
Path_Key filename
Tag <appname>.<appversion>
Tag_Regex /(?<appname>[^-]+)-(?<appversion>[^.]+).log$
Tag_Regex
用于设置可用于设置的
.< appname>
和< appversion>
变量>标记
The Tag_Regex
is used to set the <appname>
and <appversion>
variables that can be used to set the Tag
.
关于在日志条目的字段中设置这些类型的值,我找不到任何本机"字段.做到的方式.但是,通过使用 Lua过滤器,我可以实现类似的目的:>
As for setting these sort of values in a field in the log entry I couldn't find any "native" way to do it. However I was able to achieve something similar by using a Lua filter:
[INPUT]
Name tail
Path /var/log/containers/*-*.log
Path_Key filename
[FILTER]
Name lua
Match *
script helper.lua
call extract_app_fields
会调用 helper.lua
文件中的 extract_app_fields
函数:
function extract_app_fields(tag, timestamp, record)
retcode = 0
filename = record['filename']
if filename ~= nil then
appname = filename('/([^-]+)-[^.]+\.log')
appversion = filename('/[^-]+-([^.]+)\.log')
if appname ~= nil then
record['appname'] = appname
retcode = 2
end
if appversion ~= nil then
record['appversion'] = appversion
retcode = 2
end
end
return retcode, timestamp, record
end
extract_app_fields
函数从 filename
中提取 appname
和 appversion
并更新中的字段>记录
(如果可以确定的话).
The extract_app_fields
function extracts the appname
and appversion
from the filename
and updates the fields in the record
if they can be determined.
注意:我是Lua的新手,因此使用Lua可能会有更好的方法.
这篇关于FluentBit-从Path_Key进行解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!