【问题标题】:Monit gives error after first run of exec commandMonit 在第一次运行 exec 命令后给出错误
【发布时间】:2020-06-10 09:23:57
【问题描述】:

我正在运行 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] 警告:'host_name' cpu 使用率为 0.5% 符合资源限制 [cpu 使用率

[UTC Jun 6 10:10:13] 警告:“host_name”cpu 使用率为 1.6% 与资源限制相匹配 [cpu 使用率

[UTC Jun 6 10:12:13] 警告:'host_name' cpu 使用率为 0.3% 符合资源限制 [cpu 使用率

[UTC Jun 6 10:14:13] 警告:'host_name' cpu 使用率为 0.3% 符合资源限制 [cpu 使用率

[UTC Jun 6 10:16:13] 错误:'host_name' cpu 使用率为 0.3% 匹配资源限制 [cpu 使用率

[UTC Jun 6 10:16:13] info : 'host_name' exec: '/bin/bash /var/www/stop.sh'

[UTC Jun 6 10:18:13] 错误:'host_name' cpu 使用率为 0.5% 匹配资源限制 [cpu 使用率

[UTC Jun 6 10:20:13] 错误:'host_name' cpu 使用率为 0.3% 匹配资源限制 [cpu 使用率

[UTC Jun 6 10:22:13] 错误:'host_name' cpu 使用率为 0.3% 匹配资源限制 [cpu 使用率

[UTC Jun 6 10:24:13] 错误:'host_name' cpu 使用率为 0.2% 匹配资源限制 [cpu 使用率

[UTC Jun 6 10:26:13] 错误:'host_name' cpu 使用率为 0.3% 匹配资源限制 [cpu 使用率

当它出错时,它就不再工作了。

Bash 脚本正常运行。

我做错了什么?

【问题讨论】:

    标签: bash ubuntu-18.04 monit


    【解决方案1】:

    让我们分解一下要求 Monit 做什么:

    如果 cpu 使用率 然后 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 个警告(但无操作)

    如果 5 个周期的 cpu 使用率

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

    由于它没有进一步的指令,它只是重复错误(因为它仍然存在)。 如果你想让 monit 再次运行 stop.sh,你需要告诉它(以及多久),例如你可以这样做

    如果 cpu 使用率 每 5 个循环重复一次

    【讨论】:

      猜你喜欢
      • 2014-03-30
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多