【发布时间】:2020-03-20 07:08:22
【问题描述】:
在我的用例中,我有一个产生大量日志的服务,除了 loggly(第三方 ELK 作为服务)之外,日志还必须写入文件
服务配置为将json日志写入端口515
我看到一个问题,即一旦服务运行了一段时间,service_log.jsonl 中的日志就会以越来越高的速度落后。我怀疑这是由于direct_service_json 和push_loggly_service 的操作队列以某种方式耦合
理想情况下,我希望将direct_service_json 和push_loggly_service 完全解耦,这样push_loggly_service 编写器就可以将日志推送到loggly,而direct_service_json 在服务日志上保持最新
执行此操作的最佳方法是什么?我已经提供了我正在使用的配置文件 - 使用此配置,service_log.jsonl 中的日志在 30 分钟左右开始滞后
module(load="omhttp")
module(load="mmjsonparse")
module(load="imudp")
template(name="json_logs" type="list") {
constant(value="{") property(name="hostname" outname="hostname" format="jsonfr")
constant(value=",") property(name="timereported" outname="timestamp" format="jsonfr" dateFormat="rfc3339")
constant(value=",") property(name="programname" outname="proc" format="jsonfr")
constant(value=",") property(name="syslogpriority-text" outname="level" format="jsonfr")
constant(value=",") property(name="$!all-json" position.from="2")
}
template(name="simple" type="list") {
property(name="syslogtag")
property(name="msg")
constant(value="\n")
}
# Write messages to /var/log/service_logs.jsonl
ruleset(name="direct_service_json" queue.Type="LinkedList") {
action(type="omfile" file="/var/log/service_logs.jsonl" template="simple")
}
# Send messages to Loggly using the json_logs template.
# Using two consumers to handle insane log volume
# Consumers are capped at 4, rsyslog spawns workers when action is backlogged at 100
ruleset(name="push_loggly_service" queue.Type="LinkedList" queue.WorkerThreads="4" queue.workerThreadMinimumMessages="100"){
action(type="mmjsonparse" cookie="")
action(type="omhttp"
server="logs-01.loggly.com"
errorfile="/var/log/rsyslog.error.log"
restpath="inputs/SECRET_TOKEN/tag/rsyslog"
retry="on"
useHttps="on"
template="json_logs"
)
}
input(type="imudp" port="515" name="json-input")
# Hack - attempt to decouple the file writer from the loggly writer
if $inputname == "json-input" then {
call direct_service_json
}
if $inputname == "json-input" then {
call push_loggly_service
}
【问题讨论】: