我是 Logwatch 的新手,我设置它来监视由 celery(Python 世界中流行的分布式任务队列)创建的日志文件。
我的 logwatch.conf“范围”设置为“昨天凌晨 4 点到今天凌晨 4 点之间”,并且此范围过滤器适用于其他日志文件 - 但不适用于我的 celery 日志文件。
这是我的设置:
/etc/logwatch/conf/services/celery.conf
Title = "Celery worker errors"
LogFile = celery
/etc/logwatch/conf/logfiles/celery.conf
LogFile = /var/log/208-celery.log
LogFile = /var/log/234-celery.log
LogFile = /var/log/403-celery.log
LogFile = /var/log/dev-celery.log
/etc/logwatch/scripts/services/celery
#!/bin/bash
cat
问题似乎只是使用 cat 作为过滤器 - 显然这并没有过滤任何日期,只是传递了 celerry 日志文件的行。
我知道 logwatch 有一些内置的日期格式过滤器,但我不清楚如何应用它们,也不清楚它们是否适合芹菜日志的格式,如下所示:
[2016-04-26 11:59:37,851: WARNING/MainProcess] celery@big-dog ready.
[2016-04-26 11:59:37,852: DEBUG/MainProcess] | Worker: Hub.register Pool...
[2016-04-26 11:59:37,852: DEBUG/MainProcess] basic.qos: prefetch_count->16
[2016-04-26 11:59:43,146: INFO/MainProcess] Received task: hello_world[b29ef98a-d9fb-4cc6-b7db-9434a9bcc1e2]
我的问题是:如何配置 logwatch 以正确地对这些日志文件进行日期过滤?
答案1
我认为 /usr/share/logwatch/scripts/shared/applyhttpdate 文件会有所帮助。
定义芹菜的日期格式。
/etc/logwatch/scripts/shared/applycelerydate
use Logwatch ':dates';
$Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
$SearchDate = TimeFilter('%Y-%m-%d %H:%M:%S');
if ( $Debug > 5 ) {
print STDERR "DEBUG: Inside ApplyCeleryDate...\n";
print STDERR "DEBUG: Looking For: " . $SearchDate . "\n";
}
while (defined($ThisLine = <STDIN>)) {
if ($ThisLine =~ m/\[$SearchDate/o) {
print $ThisLine;
}
}
并且,将日志文件链接到日期格式。
/etc/logwatch/conf/logfiles/celery.conf
LogFile = /var/log/208-celery.log
LogFile = /var/log/234-celery.log
LogFile = /var/log/403-celery.log
LogFile = /var/log/dev-celery.log
*ApplyCeleryDate