我想在monit处理一种连锁动作 .
- 立即检查流程并发出警报 .
多次循环后 - 重启过程 .
我的尝试(到目前为止):
check process myprocess with pidfile /run/my.pid
start program = "/path/to/binary start" with timeout 60 seconds
stop program = "/path/to/binary stop" with timeout 60 seconds
if not exist for 3 cycles then restart
if not exist then alert
if 3 restarts within 3 cycles then timeout
在故障PID时不报警并保持状态“运行”,但在3个周期后重新启动 .
check process myprocess with pidfile /run/my.pid
start program = "/path/to/binary start" with timeout 60 seconds
stop program = "/path/to/binary stop" with timeout 60 seconds
if not exist for 3 cycles then restart
if children < 1 for 1 cycles then alert
if 3 restarts within 3 cycles then timeout
没有儿童的警报<1但重启5 .
monit.log
[CEST Aug 1 15:09:30] error : 'myprocess' process is not running
monit摘要
Process 'myprocess' Running
这是monit -v部分:
Existence = if does not exist 3 times within 3 cycle(s) then restart else
if succeeded 1 times within 1 cycle(s) then alert
Pid = if changed 1 times within 1 cycle(s) then alert
Ppid = if changed 1 times within 1 cycle(s) then alert
Children = if less than 1 1 times within 1 cycle(s) then alert else if
succeeded 1 times within 1 cycle(s) then alert
Timeout = If restarted 3 times within 3 cycle(s) then unmonitor
所以问题是:是否可以发送警报并在1个周期内将状态更改为“未运行”并在3个周期后重新启动?
1 回答
EDIT (IMPORTANT) :请参阅下面的评论,了解Monit的更新版本(根据2019年2月),此行为已得到改进 .
这一行:
意味着以下内容:
在检查3次服务不存在之前,请不要执行任何操作,然后重新启动它 . 在monit的文档中将此行为描述为Failure Tolerance:
因此,Monit不会改变服务的状态,直到它在接下来的X个周期内失败 . 为了确认此声明,只需删除此服务的容错,并仅使用:
手动停止服务并确认该命令
一旦停止,现在显示状态“不存在” .
那么,回到你的问题:
SMTP SERVER CONFIGURATION
(请注意,在gmail中,您必须激活“不安全”应用程序的访问权限才能允许monit使用stmp服务)
和
EMAIL RECIPIENT
两者都在文件/ etc / monit / monitrc中 . 有关这两行的更多信息,请参阅官方文档 .
参考文献:
Monit的文档:https://mmonit.com/monit/documentation/monit.html
希望能帮助到你!
问候