过滤 Syslog 中的“无用日志”通常可以从采集端、服务端、存储/分析端三个层面来做。下面按常见场景给出可落地的方法。
先定义要过滤的内容,常见包括:
debug、info)按设施/级别过滤
# 丢弃 mail.debug
:programname, contains, "cron" stop
*.debug;mail.none;authpriv.none /var/log/messages
按内容丢弃
# 丢弃包含特定关键字的日志
:msg, contains, "health check" stop
只收重要级别
*.err /var/log/error.log
重启:
systemctl restart rsyslog
filter f_noise {
not message("heartbeat") and
not facility(cron) and
level(info..emerg);
};
log {
source(s_src);
filter(f_noise);
destination(d_file);
};
filter {
if [message] =~ /heartbeat/ {
drop {}
}
if [level] == "debug" {
drop {}
}
}
<match **>
@type grep
<exclude>
key message
pattern /health check/
</exclude>
</match>
message 全文(改为 keyword)level: error and not program: cron
目标:只保留 error 以上 + 关键业务日志
rsyslog:
*.err /var/log/syslog_important.log
:msg, contains, "order failed" /var/log/syslog_important.log
*.* stop
如果你愿意,可以告诉我:
我可以直接帮你写可用的配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。