Straightforward service and metric monitoring for your servers

Straightforward service and metric monitoring for your servers

There are a lot of monitoring and observability solutions out there that all have it's purpose and justification but sometimes you want something really simple e.g. for a small server.

How about creating just one or two bash scripts that do the job? For this purpose I started the simple-server-monitoring project.

GitHub - ronnyworm/simple-server-monitoring: Easily monitor the health of your server
Easily monitor the health of your server. Contribute to ronnyworm/simple-server-monitoring development by creating an account on GitHub.

Requirements

  • Linux system
  • Ruby (at least v2.7)
  • Root access
  • SMTP credentials for the email notification
  • Basic shell scripting knowledge
  • Basic crontab knowledge

Installation and setup

1.

git clone https://github.com/ronnyworm/simple-server-monitoring
cd simple-server-monitoring
gem install mail
mv send_mail_example.rb send_mail.rb
  1. Then you need to enter your SMTP credentials to be notified when something is wrong in send_mail.rb. (Feel free to create a PR for using .env here; I had no time for that yet.)
  2. Take a look at example_check_configuration.sh to get some suggestions how to configure your own alerts e.g.
metric_check "process number" \
    "ps -e | wc -l" \
    "-gt" \
    500 \
    "$servername process number (ps -e) is greater than"

or

application_status_check "ufw status" \
    "Status: ..tiv" \
    "ufw reload" \
    "$servername ufw was not active"

(You might want to use command -v ufw to find out the location of ufw and directly use that if running this fails.)

I suggest to create yours in a new file named check_configuration.sh.

  1. Add the script execution to your root crontab with sudo crontab -e like this
30 5 * * * f=/some/folder; $f/server_monitoring.sh $f/check_configuration.sh >> $f/monitoring.log 2>&1

to run it every morning at 5:30.

The repository also contains suggestions for monitoring website health but that should really be done with Uptime Kuma which is also a simple solution with a nice UI and some additional features. It requires Docker though.

If your monitoring and alerting requirements are a bit more complex than this or if you'd like a nice UI, you should go for solutions involving Prometheus, Node Exporter, Grafana, Alert Manager and probably also Loki and Promtail which I also set up for a few clients.

How do you monitor the health of your servers when you need a very simple solution? Thanks for reading.

Impressum     Datenschutz