我有一台服务器(Ubuntu),可以管理多个域并运行一系列cron脚本。但是无法预测服务器上的负载,因此无法在cron脚本中设置正确的负载量。
但是,在cron中运行的脚本会不时地重载并在CPU和内存中产生巨大的负载,导致服务器的多个服务停止(例如邮件服务器)。
问题是:如何在服务器负载低于最小阈值时编写运行现在在cron中的例程的脚本?是否有任何应用程序在Linux下执行此操作?
感谢您的时间!
答案 0 :(得分:1)
您可以查看monit系统管理。 您可以将其添加到配置文件中:
# Monitoring the apache2 web services. # It will check process apache2 with given pid file. # If process name or pidfile path is wrong then monit will # give the error of failed. tough apache2 is running. check process apache2 with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" # Admin will notify by mail if below of the condition satisfied. if cpu is greater than 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 200.0 MB for 5 cycles then restart if children > 250 then restart if loadavg(5min) greater than 10 for 8 cycles then stop if 3 restarts within 5 cycles then timeout group server
这是一个很好的工具,您可以在满足条件时搜索如何执行自己的脚本。