Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|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. –  Francisco 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
    
For future wanderers: my advice in this situation is to login while it's acting up (if you can) and run show full processlist; that will tell you what the server is doing at the moment. –  Eli Jun 10 at 22:59

2 Answers 2

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.

share|improve this answer

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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