Monitoring Website for Downtime

Sometimes our in house server go down, But at production level we cannot take risk of 1min downtime, so we were supposed to monitor our server for downtime.
Although there are many cheap services available but i decided to do it my own way, I can use this script in my RPI to monitor even my internal services.

Below is python code, Which sends email if a server goes down and when it comes back online. Obviously you can add code to get more statistics like Logging to file, average response time, Monitoring page changes, Downtime etc.

After saving code to server use cron job to start run script on every boot.

Edit crontab using sudo crontab -e and then add following line to file.

@reboot screen -dmS monitor python /root/monitor.py &> /dev/null

Above command starts a screen session named monitor and forwards error of screen to null.
Incase you want to see output of monitor.py use screen -r monitor.
You can also add it simply without screen like
@reboot python /root/monitor.py &

If you have some suggestions comment.

Published by

Madhurendra

Newbie (Student, Developer, Programmer and Electronic Hobbyist)

Leave a Reply

Your email address will not be published. Required fields are marked *