我正在运行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 6月6日10:08:13信息:'host_name‘Monit重新加载
UTC 6 10:08:13警告:'host_name‘cpu使用率0.5%匹配资源限制cpu使用率< 30.0%警告:'host_name’cpu使用率1.6%匹配资源限制cpu使用率< 30.0%警告:'host_name‘cpu使用率0.3%匹配资源限制cpu使用率< 30.0%警告:'host_name’cpu使用率0.3%匹配资源限制cpu使用率< 30.0%错误:'host_‘命名‘cpu使用率0.3%匹配资源限制cpu使用率< 30.0%信息:'host_name’exec:'/bin/bash /var/www/top.sh‘
UTC 06 10:18:13错误:'host_name‘cpu使用率0.5%与资源限制cpu使用率< 30.0%错误:'host_name’cpu使用率0.3%匹配资源限制cpu使用率< 30.0%错误:'host_name‘cpu使用率0.3%匹配资源限制cpu使用率< 30.0%错误:'host_name’cpu使用率0.2%匹配资源限制cpu使用率< 30.0%错误:“host_name”cpu使用率为0.3%,与资源限制相匹配& of;30.0%
当它产生错误时,它就不再起作用了。
Bash脚本运行时没有错误。
我做错什么了?
发布于 2020-07-16 21:29:47
让我们打破蒙尼特被要求做的事情:
如果5个周期的使用率< 30%,则执行 "/bin/bash /var/www/.30“
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使用率< 30%,那么exec "/bin/bash /var/www/. if“
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'我们已经进入了第五个周期,它现在被认为是一个错误,并且运行/var/www/ the .the
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,则需要告诉它(以及每隔多长时间)您可以这样做。
如果
使用率低于30%,则exec "/bin/bash /var/www/sto.sh“每5个周期重复一次
https://stackoverflow.com/questions/62300093
复制相似问题