过滤 Syslog 中的“无效日志”通常指丢弃噪声、重复、无关或不符合规范的日志,只保留有价值的信息。可以从采集端、服务端、分析端三个层面来做。下面按“实践可落地”的方式说明。
常见类型包括:
按优先级过滤
# 丢弃 debug 级别
if ($syslogseverity <= 7) then stop
按程序名过滤
if ($programname == "cron") then stop
按正则过滤
if ($msg contains "heartbeat") then stop
丢弃不符合格式
if ($syslogfacility-text == "kern" and $msg == "") then stop
filter f_noise {
not match("heartbeat") and
not priority(debug);
};
log {
source(s_src);
filter(f_noise);
destination(d_file);
};
filter {
if [priority] == 7 {
drop {}
}
if [message] =~ /heartbeat/ {
drop {}
}
}
[transforms.filter]
type = "filter"
condition = '.message contains "noise"'
| 维度 | 示例 |
|---|---|
| 主机 | 丢弃测试机日志 |
| 程序 | 丢弃 dockerd |
| 级别 | 只保留 warning+ |
| 关键字 | 丢弃 ping ok |
| 频率 | 同类日志限流 |
频率限流(rsyslog)
module(load="impstats")
if ($programname == "sshd") then {
if (repeated_msg_reduction()) then stop
}
rsyslog 示例:
if ($timereported == "") then stop
小规模
rsyslog 本地规则 + 白名单
中大型
采集端粗过滤 → 服务端细过滤 → 分析端采样
云平台
Syslog → Kafka → Flink 去重 → ES
如果你能告诉我:
我可以直接给你可复制的配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。