【问题标题】:capture multiline events with rsyslog and storing them to file使用 rsyslog 捕获多行事件并将它们存储到文件中
【发布时间】:2021-05-14 03:39:57
【问题描述】:

我们有一个集中的 rsyslog 基础设施,用于捕获来自世界各地的设备使用 imtcp 模块发送的 TCP 事件。

这个想法是从 syslog (TCP) 读取并将事件存储到磁盘,每个事件一行。这些事件稍后由其他消费者处理。

据我们所见,一些事件一旦存储在磁盘上就会拆分为多个事件,从而破坏了我们的其余进程。

使用 tcpdump 捕获单个包,我们确认源 syslog 正在向我们发送包含多行的整个事件(典型的 java 异常)。

[root@xx xx.xx.xx.xx]# tcpdump -i bond0 tcp port 50520 -A -c 1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on bond0, link-type EN10MB (Ethernet), capture size 262144 bytes
12:12:26.062110 IP xx.xx.xx.xx.com.41444 > xx.xx.xx.com.50520: Flags [P.], seq 3270590174:3270590613, ack 2646946316, win 27, options [nop,nop,TS val 3937801207 ecr 2623497312], length 439
E....`@.<.ML..A....N...X..>...2......q.....
....._d`<13> xxx #2.0.#2021 02 10 12:19:50:898#+00#Info#com.xx.xx.xx.xx.xx#
##JavaEE/xx#xx#xx#JavaEE/xx#com.xx.xx.xx.xx.APIServiceHandler#xx#xx##xx#xx##0#Thread[HTTP Worker [@xx],5,Dedicated_Application_Thread]#Plain##
Is the user getting thru SSO? xx:true#

1 packet captured
44 packets received by filter
2 packets dropped by kernel

由于这是一个全球系统,我们不能要求设备所有者修改格式,所有操作都应该在我们这边进行。

这是我们的 rsyslog.conf 文件

$MaxMessageSize 128k
# Global configuration/modules
module(load="imtcp" MaxListeners="100")
module(load="imfile" mode="inotify")
module(load="impstats" interval="10" resetCounters="on" format="cee" ruleset="monitoring")
module(load="mmjsonparse")
module(load="mmsequence")
module(load="omelasticsearch")
module(load="omudpspoof")

# Include all conf files
$IncludeConfig /etc/rsyslog.d/*.conf

这是我们的模板,它从 tcp 读取并写入文件 (etc/rsyslog.d/template.conf)

template(name="outjsonfmt_device" type="list") {
         constant(value="{")
         property(outname="device_ip" name="fromhost-ip" format="jsonf")
         constant(value=",")
         property(outname="time_collect" name="timegenerated" dateFormat="rfc3339" format="jsonf")
         constant(value=",")
         constant(value="\"device_type\":\"device\"")
         constant(value=",")
         property(outname="collector_id" name="$myhostname" format="jsonf")
         constant(value=",")
         property(outname="msg" name="rawmsg-after-pri" format="jsonf" )
         constant(value="}\n")
}

template(name="device-out-filename" type="string" string="/data1/input/device/%fromhost-ip%/device_%$now-utc%_%$hour-utc%.log")
ruleset(name="writeRemoteDataToFile_device") {
         action(type="omfile" dynaFileCacheSize="10000" dirCreateMode="0700" FileCreateMode="0644" dirOwner="user" dirGroup="logstash" fileOwner="user" fileGroup="user" dynafile="device-out-filename" template="outjsonfmt_device")
}
input(type="imtcp" port="50520" ruleset="writeRemoteDataToFile_device")

在将事件写入磁盘之前,我们如何配置 rsyslog 以避开事件中间的换行符?我们已经尝试过 $EscapeControlCharactersOnReceive 没有成功和其他类似的参数

【问题讨论】:

    标签: tcp line-breaks multiline syslog rsyslog


    【解决方案1】:

    imtcp 有一个模块参数DisableLFDelimiter,您可以尝试将其设置为on 以忽略换行分隔符,假设您的输入有一个八位字节计数标题。该页面说,这种模式是非标准的,可能会带来很多问题。

    module(load="imtcp" MaxListeners="100" DisableLFDelimiter="on")
    

    【讨论】:

    • 我们已经尝试了 DisableLFDelimiter 并将 AddtlFrameDelimiter 设置为 10 和 13(换行符)。主要问题是 DisableLFDelimiter 从消息中删除所有 LF 字符,甚至是用于确定消息结尾的字符。这会将所有消息连接到一个大消息中
    猜你喜欢
    • 2021-06-10
    • 2022-12-23
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 2015-03-04
    相关资源
    最近更新 更多