重复监控警报

重复监控警报

我怎样才能让 monit 持续每隔一段时间提醒我,直到问题得到解决?这是一个示例配置:

检查文件系统 datafs 路径为 /dev/sda1
  如果 15 个周期内 5 次空间使用率 > 80%,则发出警报

在这里,我会收到一次警报,然后就再也没有了。我希望 monit 在问题解决之前一直处于关闭状态。

答案1

来自 monit 手册页:

alert foo@bar with reminder on 1 cycle

每次进程检查重复处于失败状态时(例如,多次),都会重复发出警报。您可能希望将其设置为仅每小时或更短时间提醒您

这似乎是在您设置警报目标的位置设置的,而不是在检查节中设置的。但是,您可以为单个检查/服务以及全局检查/服务指定警报目标。

check filesystem datafs with path /dev/sda1
  alert foo@bar on { resource } with reminder on 10 cycles
  if space usage > 80% for 5 times within 15 cycles then alert

答案2

默认设置是当触发器匹配时发出警报,当服务成功时再次发出警报。因此,如果磁盘利用率在 79% 和 81% 之间波动,则在达到阈值时您会收到警报。

但是,您希望在触发警报后收到提醒。您可以使用提醒功能在 Monit 中执行此操作。

以下是 Monit 的示例配置:

For example if you want to be notified each tenth cycle if a service remains in a failed state, you can use:

  alert foo@bar with reminder on 10 cycles
Likewise if you want to be notified on each failed cycle, you can use:

  alert foo@bar with reminder on 1 cycle

您可以使用以下语言来扩展您的诗节:

check filesystem datafs with path /dev/sda1
  if space usage > 80% for 5 times within 15 cycles then alert 

但您必须修改全局set alert语句或在检查节级别进行更改:

set alert [email protected] with reminder on 5 cycles

答案3

如果通知是通过自定义可执行文件完成的,那么您可以使用重复周期来处理重复。

例如

check filesystem rootfs with path /
  # notify every 5 minutes that the disk usage is over 95%.
  if space usage > 95% then exec "/opt/monit/monit-slack-notify.sh" repeat every 5 cycles
    # also notify when it's recovered.
    else if succeeded then exec "/opt/monit/monit-slack-notify.sh"

有更多参考资料这里

相关内容