There are many ways to monitor a server, one of them is using Monit, a tool which will always check the services running on the server and it can send alert when there is a problem.
Monit also has the ability to restart any service with some triggers.
Here are an example of Monit config to use Yandex’s SMTP for email alerts.
set mailserver smtp.yandex.com port 587
username "email@example.com" password "p4$W0_rD"
set alert firstname.lastname@example.org
check system vmi69564.contabo.host
if memory usage > 80% for 2 cycles then alert
if cpu usage (user) > 70% for 2 cycles then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
if loadavg (1min) > 6 for 2 cycles then alert
if loadavg (5min) > 4 for 2 cycles then alert
if swap usage > 5% then alert
check filesystem rootfs with path /
if space usage > 80% then alert
That’s it. 🙂