I'm running mysql on Debian.

Is there a way to monitor mysql and restart it automatically if it locks up? For example sometimes the server starts to take 100% of cpu and starts running very slowly. If I restart mysql, things clear up and the server starts working fine, but I'm not always present to restart it manually.

Is there a way to monitor mysql and if the cpu is above 95% for more than 10 minutes straight then then mysql will automatically be restarted

link|improve this question

5  
Apart from any answer recommending solutions to the issue of restarting the MySQL server, I strongly recommend you to investigate where those 100% CPU load spikes come from. That's the "real problem", and restarting the server will, IMVHO, never be a permanent and proper solution. – Fran Jan 22 '11 at 22:58
Indeed, that's the tension between 'get it fixed now' and 'get it fixed right'. – Phil Hollenback Jan 28 '11 at 22:14
feedback

2 Answers

up vote 1 down vote accepted

You can do this with monit. For example, to alert & restart mysql, assuming you run monit on a 60 second cycle:

check process mgsqld
  with pidfile /var/run/mysqld.pid
if cpu usage > 99% for 10 cycles then alert
if cpu usage > 99% for 10 cycles then restart

monit is very flexible and can do pretty much any sort of monitoring of processes, memory, etc. you can think of.

This could probably be done with ps-watcher too, but it's hard to make ps-watcher remember this sort of state and act on it. monit is the right tool to use.

link|improve this answer
feedback

I belive you're looking for and the Auto Nice Daemon.

link|improve this answer
3  
No, that doesn't solve the problem. If the process locks up, reducing it's priority won't help. – SvenW Jan 22 '11 at 23:18
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.