【问题标题】:Handling large log volume in rsyslog with omhttp and omfile使用 omhttp 和 omfile 处理 rsyslog 中的大量日志
【发布时间】:2020-03-20 07:08:22
【问题描述】:

在我的用例中,我有一个产生大量日志的服务,除了 loggly(第三方 ELK 作为服务)之外,日志还必须写入文件

服务配置为将json日志写入端口515

我看到一个问题,即一旦服务运行了一段时间,service_log.jsonl 中的日志就会以越来越高的速度落后。我怀疑这是由于direct_service_jsonpush_loggly_service 的操作队列以某种方式耦合

理想情况下,我希望将direct_service_jsonpush_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
}

【问题讨论】:

    标签: logging rsyslog


    【解决方案1】:

    根据一位主要 rsyslog 维护人员的建议,我成功地将主队列与操作队列分离。

    我使用impstats 模块来监控我的队列,因为他们发现了瓶颈。

    使用我的配置,主队列与 push_loggly 操作队列一起不断增长

    我从这里更改了我的规则集

    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"
                    )
            }
    
    

    到这个。我只是从规则集中取出队列参数并将它们放入 omhttp 操作中。显然,这会创建一个与主消息队列分离的操作队列。

    ruleset(name="push_loggly_service"){
            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"
                    queue.Type="LinkedList"
                    queue.Size="300000"
                    queue.workerthreadminimummessages="200"
                    queue.workerthreads="2"
                    )
            }
    

    我可以接受 omhttp 队列被积压 - 只要它不会减慢整个日志记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 2018-04-26
      • 2014-11-06
      相关资源
      最近更新 更多