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

When a server uses memory more than available RAM, the system will shut down the virtual machine. Then, it is only possible to boot from outside (VPS control panel, e.g. vePortal or SolusVM). However, it should be possible to plan a reboot before possible shut down.

What is the best practical method to check the used memory, and reboot the system upon reaching e.g. 90% of the allowed RAM? Is there a common program or script to do so? I am using Debian/Ubuntu.

share|improve this question
    
Who is this provider that shuts it down instead of rebooting? Seems a bit of an odd way to handle the problem. –  Grant Sep 11 '12 at 14:41
    
@Grant Most of budget VPS providers :-) they wish to find excuse to reduce overload on oversold servers. –  All Sep 11 '12 at 15:24
    
No virtual memory and no caching? It's a bit odd to defeat what Linux sets out to do by utilising all available memory. –  Steve-o Sep 11 '12 at 16:54

3 Answers 3

Nagios could do it, but Monit is pretty much designed for exactly this problem and can be configured to restart services or the whole machine in low memory situations.

I use it on several servers to check for run away processes using excessive memory and restart them. I find it a lot easier to configure than nagios actions.

It's also useful for checking if services have failed and restarting them.

The relevant part of monitrc would look like:

check system myserver
  if memory usage > 90% then restart

Nice and simple :)

share|improve this answer

Instead of cutting the branches, you should cut the root of problem. Try to analyze that which process or activity eats up all the RAM. and fix that activity, instead of rebooting server everything when RAM files up 90%. you can use nagis for this purpose, that if RAM gets 90% fill, call an Event handler which will shutdown or reboots the server.

share|improve this answer
    
It is not a routine problem, it is rare overload or even attack or even unpredictable problem (which can be solved by reboot). It cannot be bad to make sure that the server will always go back online upon any failure. –  All Sep 11 '12 at 13:50
    
Nagios server with Events handlers is the best solution –  Farhan Sep 11 '12 at 13:53

This is not advisable to reboot your VPS using script.

If your server goes out of memory at each boot time then your server never been up.

So, I will suggest you to use VPS management Control Panel for this.

share|improve this answer

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.