在Debian 8服务器上,我有monit 5.9-1
设置并监控多个服务。我计划在1.26-2
上进行监控,我可以使用以下配置
check process atop with pidfile /var/run/atop.pid
group system
group atop
start program = "/usr/sbin/service atop start"
stop program = "/usr/sbin/service atop stop"
这很好用。但是我偶尔会注意到/var/log/messages
中的以下条目:
traps: atop[8810] trap divide error ip:40780a sp:7ffdf663cdc8 error:0 in atop[400000+26000]
当发生这种情况时,atop不会创建每日日志文件/var/log/atop/atop-$( date '+%Y%m%d' )
,因此尝试运行atop -r 20160127 -b 15:00
会导致输出
/var/log/atop/atop_20160127 - open raw file: No such file or directory
我一直试图让monit检查是否存在日志文件,如果通过将上面的配置更改为
而丢失则重新启动date=$( date '+%Y%m%d' )
check process atop with pidfile /var/run/atop.pid
group atop
start program = "/usr/sbin/service atop start"
stop program = "/usr/sbin/service atop stop"
depend on atop_log
check file atop_log with path /var/log/atop/atop-$date
group atop
它没有抱怨它不会扩展变量。
如果有可能/怎么做,任何人都有任何想法?
答案 0 :(得分:1)
我找到的解决方案是使用bash脚本检查文件是否存在,monit调用bash脚本。
使用以下内容创建文件/etc/monit/scripts/atop-log-check.sh
:
#!/bin/bash
if [ -f "/var/log/atop/atop_$( date '+%Y%m%d' )" ]; then
exit 0
else
exit 1
fi
chmod to 500然后将monit config更新为:
check process atop with pidfile /var/run/atop.pid
group atop
start program = "/usr/sbin/service atop start"
stop program = "/usr/sbin/service atop stop"
check file atop-log-check path /etc/monit/scripts/atop-log-check.sh
group atop
if changed checksum then alert
if failed permission 500 then alert
if failed uid root then alert
check program atop_log path /etc/monit/scripts/atop-log-check.sh
group atop
if status != 0 then restart