【问题标题】:M/Monit config file variable expansionM/Monit 配置文件变量扩展
【发布时间】:2016-01-27 17:17:22
【问题描述】:

在 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]

发生这种情况时,top 不会创建每日日志文件 /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

它不会抱怨它不会扩展变量。

如果可能/如何做到这一点,有人有任何想法吗?

【问题讨论】:

    标签: linux debian config monit variable-expansion


    【解决方案1】:

    我找到的解决方案是使用 bash 脚本来检查文件是否存在,并且 bash 脚本由 monit 调用。

    使用内容创建文件/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 为 500,然后在 monit 配置上更新为:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 2014-11-08
      • 2011-02-19
      相关资源
      最近更新 更多