Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
|
I must be tired, but I don't understand....
You have a cpu intensive job that must run.
This job is set as a service (/etc/init.d/whatever start|stop|restart).
You want to be able to restart the service if the cpu usage is too high.
First, if the cpu usage is caused by your service, what good will it do to restart it ?
Second, you say
Quote:
|
how to add the cpu > 10 then -restart the services-
|
...
what is the ">10" part ?
a cpu usage greater than 10 percent, an application cpu time greater than 10 minutes, an average system load greater than 10?
Task management with action taken on a given event, is not something that exists de-facto in the linux kernel, afaik.
So, either you have a program that handle that, or you might implement it via a script that run every minutes (via the cron system).
I assume here that you will take the second way.
If you are talking about the system avg load, such a script could be easily done with:
Code:
uptime|cut -d',' -f5
which gives you the 5 minutes average system load.
Full logic would be:
Code:
#!/bin/bash
LOAD=`uptime |cut -d',' -f5`;
echo "5 minutes average load is :$LOAD"
if [[ "$( echo "${LOAD}>10" | bc )" == '1' ]]; then
echo 'restarting service';
/etc/init.d/whatever restart;
else
echo "Load of ${LOAD} is low enough";
fi;
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 08-26-2009 at 12:04 PM..
|