Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
quick cpu grep if then script help pls
Old 08-26-2009, 11:19 AM quick cpu grep if then script help pls
globalamp's Avatar
Novice Talker

Latest Blog Post:
General Dramatically smart
Posts: 11
Trades: 0
i have some pretty intense jobs that run on this centos box and want to monitor the cpu usage. if the cpu usage gets to high i want to restart those services.

i know how to restart the services but i'm not sure how to add the cpu > 10 then -restart the services-

any thoughts?

thanks!
__________________

Please login or register to view this content. Registration is FREE
/
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
(Getting ready to launch)
globalamp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2009, 12:01 PM Re: quick cpu grep if then script help pls
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-26-2009, 12:37 PM Re: quick cpu grep if then script help pls
globalamp's Avatar
Novice Talker

Latest Blog Post:
General Dramatically smart
Posts: 11
Trades: 0
i think that might do it. i was talking about load averages. if they go over 10 or 20 i want to stop a job and restart a few services.

i'll give that a try and see what happens.

thank you!!
__________________

Please login or register to view this content. Registration is FREE
/
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
(Getting ready to launch)
globalamp is offline
Reply With Quote
View Public Profile
 
Old 08-26-2009, 01:36 PM Re: quick cpu grep if then script help pls
globalamp's Avatar
Novice Talker

Latest Blog Post:
General Dramatically smart
Posts: 11
Trades: 0
i get bc command not found. thoughts?
__________________

Please login or register to view this content. Registration is FREE
/
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
(Getting ready to launch)
globalamp is offline
Reply With Quote
View Public Profile
 
Old 08-26-2009, 03:32 PM Re: quick cpu grep if then script help pls
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then install it.
If you can restart a job, then it means you have a shell access to the server.

I don't know which distribution you use, so I don't know which command to use.
It could by "yum install bc" (red-hat / fedora derivatives), or "apt-get install bc" (debian/ubuntu derivatives), or in my case "emerge bc" (gentoo).
Or one in many many others...

The point is that bash (and by extend, sh) cannot do comaprison on float numbers.
Bc is used as a calculator, to do that comparison. it receives the string "0.45<10" (for exemple) and return 0 is false, or 1 if true.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 08-26-2009 at 03:34 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-26-2009, 03:58 PM Re: quick cpu grep if then script help pls
globalamp's Avatar
Novice Talker

Latest Blog Post:
General Dramatically smart
Posts: 11
Trades: 0
wow... that's cool! thanks!

it now stops the job and then restarts the services i want.
__________________

Please login or register to view this content. Registration is FREE
/
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
(Getting ready to launch)
globalamp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to quick cpu grep if then script help pls
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17139 seconds with 12 queries