Reputation: 3024
I have a server (Ubuntu) that servers several domains and runs a series of cron scripts. However the load on the server cannot be predicted therefore I cannot set the right amount of load in the cron scripts.
However the scripts that run in cron are overloading from time to time and generate a huge load in both CPU and memory causing several services of the server to stop (such as mail server for example).
The question is: how can I write a script that runs the routines that are now in cron only when the server load is below a minimum threshold? Is there any application that does this under Linux?
Thank you for your time!
Upvotes: 2
Views: 1200
Reputation: 2568
You can check the monit system management. You can add this into your configuration file:
# 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
It is a good tool and you can search how to execute your own script when a condition satisfied.
Upvotes: 1