LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices

Reply
 
LinkBack Search this Thread
Old 05-11-2006, 08:48 AM   #1
makkintosh
Member
 
Registered: Nov 2003
Location: Moscow-city
Distribution: Gentoo Forever
Posts: 40

Rep: Reputation: 15
Lightbulb USEFULL: controlling CPU usage of some services'


Hi all! i want to share this usefull script to others.
I wrote it when we had a buggy web-site engine,that causes our mysql server to use 99% of CPU.
We couldnot find problem in website.
While we were developing new version of site i wrote a simple script whos goal was restart sql server automaticly.

Tested on freebsd.
Will not work if mysql compiled with LINUXTHREADS=yes key. because "ps" will return several lines. but only one line is expected.

Im starting this script by another script that liyng in rc.d directory.
# cat /usr/local/etc/rc.d/mysql_restarter.sh
Code:
#!/bin/sh
echo "Starting PROTECTION SCRIPT by makkintosh"
nohup /root/mysqlctl.php &
# cat /root/mysqlctl.php
Code:
#!/bin/sh
while [ -f /bin/sh ]
do
starttime=`ps -clax | grep mysqld | awk ' $1 { print $12 }' |  awk -F":" ' $2 { print ($1*60+$2)*100 }'`
sleep 2
endtime=`ps -clax | grep mysqld | awk ' $1 { print $12 }' |  awk -F":" ' $2 { print ($1*60+$2)*100 }'`
echo $endtime;
inc=`expr $endtime - $starttime`
if
test $inc -ge 124
then
/usr/local/etc/rc.d/mysql-server.sh stop
sleep 1
date >> /var/log/mysql/restarts
/usr/local/etc/rc.d/mysql-server.sh start >> /var/log/mysql/restarts
echo "mysql restarted $inc" >> /var/log/mysql/restarts
else
fi
sleep 5
done
if u need some more comments - u may ask
i hope this will help somebody
in addition there is a script called "mysql-checker.pl"
it is avalible at sf.net
it sends email to u when test queryes cannot be executed.

Good luck

P.S.
if any improvements can be done - please tell me :-)
 
  


Reply

Tags
bsd, control, freebsd, mysql, rcd, script


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Monitoring and controlling Windows services from Linux through WMI alex r Linux - Software 4 05-09-2005 06:55 AM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
Controlling user memory/cpu usage JamesF1 Linux - General 0 10-19-2004 01:41 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM


All times are GMT -5. The time now is 08:34 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration