• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question How To Create A Task That Will Reboot The Server When CPU / Memory Load Is High?

jhernanper

New Pleskian
Server operating system version
Debian 11.7
Plesk version and microupdate number
Plesk Obsidian 18.0.55
Hi everyone,

Is there a way we can create an automated task, so that when the CPU or Memory load are high, the server will reboot?

I am having high CPU peaks that make the server go down, due to PHP-FPM going crazy. I would love to monitor de PHP-FPM using 360 Monitoring but I couldn't make the PHP-FPM plugin work and opened a ticket.

So, in the meantime, being able to let the server reboot automatically when such peaks make it go down, would be awesome.

I tried to create a CRON task but there is no way to add a condition such as "when CPU usage is above x%".

Any ideas? Is there maybe a plugin for that? Or maybe with Zapier? Has anyone tried to create a script that would execute when a 360 Monitoring notification arrives by email?

Javier
 
There is no such event trigger. It may also be not a good solution to reboot the whole server on such an event. Instead, maybe you can restart the PHP-FPM processes, the web server. I would not even do it at all, but rather check what php-fpm processes exist (ps aux | grep php-fpm), because that will reveal who causes the excessive load. From there you could check the log files of the culprit and either block bad bots or ip addresses that are hitting the server with too many requests, e.g. using Plesk Firewall or directly adding them into iptables.

If you absolutely want to reboot the whole server, you could run a PHP script from cron like
Code:
$load_threshold = <decimal value that defines what cpu load is too much cpu load>
$load = shell_exec('/usr/bin/uptime');
// format the output to our likings
$load = trim(substr($load, strpos($load, 'load average:')+13));
$load = str_replace(',', '', trim(substr($load, 0, strpos($load, ' '))));
echo('CPU load ' . $load . ' ... ');
$load = floatval($load);
// test if cpu load is above the threshold
if ($load > $load_threshold) {
   shell_exec('/usr/sbin/reboot');
}
The same solution could also be done from a shell script, because this could also read the output of "/usr/bin/uptime" and issue /usr/bin/reboot if that value exceeds a defined threshold.

But again, such reboots are not advised, they are a flawed "solution" and will only work for a very short time. You'll be rebooting your server over and over again. As each reboot also carries the risk that the server won't boot at all, it's a rather bad workaround.
 
It is not an answer for the question to be honest, but I don't like the idea to reboot the whole server because of some crazy load generated by some part of some website. IMHO, a reboot should occur in cases where it is really required (kernel security updates), or in extreme cases when it cannot be avoided (the whole server works in wrong/uncontrollable way).

My opinion is a website ("=noisy neighbour"), should not affect other websites on the same server. If you know what exactly website makes php-fpm become crazy, what about configure the website to use dedicated php-fpm and control consumption of resources with CGroups [Manager] (if a Plesk license allow this; WebPro and WebAdmin)? See (Plesk for Linux) Cgroups Manager.
 
Last edited:
Back
Top