Monit 在执行命令的第一个 运行 后给出错误
Monit gives error after first run of exec command
我正在 运行ning Monit 监控 DigitalOcean 上 ubuntu 服务器上的 cpu 使用情况。
然后执行一些命令来启动或停止负载平衡器后面的其他服务器。
这是我的代码;
check system host_name
if cpu usage > 50% for 5 cycles then exec "/bin/bash /var/www/start.sh"
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
并且在第一个 运行 之后,Monit 关闭一台服务器并进入错误模式。
这是日志的一部分;
[UTC Jun 6 10:08:13] info : 'host_name' Monit reloaded
[UTC Jun 6 10:08:13] warning : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:10:13] warning : 'host_name' cpu usage of 1.6% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:12:13] warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:14:13] warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:16:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:16:13] info : 'host_name' exec: '/bin/bash /var/www/stop.sh'
[UTC Jun 6 10:18:13] error : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:20:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:22:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:24:13] error : 'host_name' cpu usage of 0.2% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:26:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
当它报错时,它就不再工作了。
Bash 脚本运行正常。
我做错了什么?
让我们分解一下要求 Monit 执行的操作:
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
warning : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 1.6% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
您的 cpu 使用率低于 30%,因此您收到 4 警告(但未采取任何措施)
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
info : 'host_name' exec: '/bin/bash /var/www/stop.sh'
我们已经到了第 5 个周期,它现在被认为是一个 错误 并且 /var/www/stop.sh 是 运行
error : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.2% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
由于它没有进一步的指示,它只是重复错误(因为它仍然存在)。
如果你想再次监视 运行 stop.sh,你需要告诉它(以及多久),例如你可以做
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
repeat every 5 cycles
我正在 运行ning Monit 监控 DigitalOcean 上 ubuntu 服务器上的 cpu 使用情况。 然后执行一些命令来启动或停止负载平衡器后面的其他服务器。
这是我的代码;
check system host_name
if cpu usage > 50% for 5 cycles then exec "/bin/bash /var/www/start.sh"
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
并且在第一个 运行 之后,Monit 关闭一台服务器并进入错误模式。 这是日志的一部分;
[UTC Jun 6 10:08:13] info : 'host_name' Monit reloaded
[UTC Jun 6 10:08:13] warning : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:10:13] warning : 'host_name' cpu usage of 1.6% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:12:13] warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:14:13] warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:16:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:16:13] info : 'host_name' exec: '/bin/bash /var/www/stop.sh'
[UTC Jun 6 10:18:13] error : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:20:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:22:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:24:13] error : 'host_name' cpu usage of 0.2% matches resource limit [cpu usage < 30.0%]
[UTC Jun 6 10:26:13] error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
当它报错时,它就不再工作了。
Bash 脚本运行正常。
我做错了什么?
让我们分解一下要求 Monit 执行的操作:
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
warning : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 1.6% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
warning : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
您的 cpu 使用率低于 30%,因此您收到 4 警告(但未采取任何措施)
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh"
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
info : 'host_name' exec: '/bin/bash /var/www/stop.sh'
我们已经到了第 5 个周期,它现在被认为是一个 错误 并且 /var/www/stop.sh 是 运行
error : 'host_name' cpu usage of 0.5% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.2% matches resource limit [cpu usage < 30.0%]
error : 'host_name' cpu usage of 0.3% matches resource limit [cpu usage < 30.0%]
由于它没有进一步的指示,它只是重复错误(因为它仍然存在)。 如果你想再次监视 运行 stop.sh,你需要告诉它(以及多久),例如你可以做
if cpu usage < 30% for 5 cycles then exec "/bin/bash /var/www/stop.sh" repeat every 5 cycles