rsyslog处理大量冗余message

一年前给 Buffalo LS-WXL 重新灌了 Debian Wheezy 后,貌似 smartd/smartctl 和原先的 kernel “水土不服“,dmesg 中频繁打印:

program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO

估计是 smartctl 对 marvell 的支持滞后了,刚开始也懒得理它,后来发现打印是在太频繁了,导致 /var/log 下的日志文件占用了太多的空间:

Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 10:00:21 HOME-NAS kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO

在不想花费太多时间的情况下,想到从 rsyslog 下手,有两种方式:

方法一:合并重复的message,合并输出

在 /etc/rsyslog.conf 中加入
###########################
#### GLOBAL DIRECTIVES ####
###########################
$RepeatedMsgReduction on

最终日志文件会生成如下内容:
Jan 19 18:01:34 home-nas kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO
Jan 19 18:02:05 home-nas kernel: last message repeated 9 times
Jan 19 18:03:06 home-nas kernel: last message repeated 28 times
Jan 19 18:04:07 home-nas kernel: last message repeated 29 times
Jan 19 18:05:25 home-nas kernel: last message repeated 30 times
Jan 19 18:06:32 home-nas kernel: last message repeated 53 times
Jan 19 18:07:32 home-nas kernel: last message repeated 28 times
Jan 19 18:08:32 home-nas kernel: last message repeated 28 times

方法二:过滤不需要记录的message,完全禁止输出
在 /etc/rsyslog.conf 中加入
###############
#### RULES ####
###############

:msg, contains, "program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO" ~

注意:末尾的~符号是同一行,格式为:
:msg contains "要匹配的文本" ~

完美解决~~~

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *