【发布时间】:2023-03-24 16:00:01
【问题描述】:
我们有一个设置,其中程序以遵循 GELF 规范的格式记录到 .Json 文件。
目前这是使用 HTTP 发送到 Graylog2 服务器。这是可行的,但由于 HTTP 的性质,存在很大的延迟,如果有大量日志消息,这是一个问题。
我想将 HTTP 传输方式更改为 UDP,以便“一劳永逸”。
日志被写入这样的文件:
{ "short_message": "<message>", "host": "<host>", "full_message": "<message>", "_extraField1": "<value>", "_extraField2": "<value>", "_extraField3": "<value>" }
目前的配置是这样的:
<Extension json>
Module xm_json
</Extension>
<Input jsonLogs>
Module im_file
File '<File Location>'
PollInterval 5
SavePos True
ReadFromLast True
Recursive False
RenameCheck False
CloseWhenIdle True
</Input>
<Output udp>
Module om_udp
Host <IP>
Port <Port>
OutputType GELF_UDP
</Output>
通过此设置,部分 json 日志消息被添加到 GELF 消息的“消息”字段,并发送到服务器。
我已尝试添加行 `Exec parse_json(),但这只会导致除 short_message 和 full_message 之外的所有字段都被排除。
我不确定如何正确配置它。即使只是将完整的日志消息添加到字段中也是可取的,因为我可以在服务器端添加一个提取器。
【问题讨论】: