An Easy Way to Monitor a Website's Health

Curious software engineer
Search for a command to run...

Curious software engineer
No comments yet. Be the first to comment.
In this series, I will treat subjects related to software development, software engineering, and related career.
If there's something I always liked in Linux is the shell! Windows has for too long been awful on that front. Nowadays on Windows, there are several solutions: PowerShell, Linux Subsystem, Git Bash, Cygwin, etc. For several years I was using cmder i...
It’s the summer holidays, after all. So I wanted to spent some time with my 7 years old daughter to teach her programming. ⌨️ I spent some time before discussing with her some of the basics concept verbally: the different parts of a computer, and bas...

This article is a follow up on my previous one introducing the concept of SE Spectrum: https://sonny.alvesdi.as/a-better-way-to-discuss Existing solutions For long, the easiest way to run a spectrum was to use visual drawing or diagram tools like ...

Introduction to SE Spectrum

One of the greatest tool available on GitHub is Dependabot. For those not familiar with it, in short it's a bot reviewing your list of dependencies and proposing PRs to update them. https://docs.github.com/en/code-security/getting-started/dependabot-...

Photo by Harli Marten on Unsplash As long as I remember I have always been interested by skepticism. And I think one element that really resonated with me has been that conference talk by Phil Plait: https://www.youtube.com/watch?v=FrFRbGjUtJk 15 ...

Recently the docker daemon running a wiki I host got into a bad state. My wiki ended up returning an HTTP error 403 for 3 days until I get poked by users.

To avoid such a situation in the future, I decided to look for an automated health check.
I found an easy and quick solution using the website healthchecks.io.
They even have a free tier for hobbyists with up to 20 jobs.
I created an account and a job there. Got my ping URL!
After I wrote a script healthcheck.sh that I ended up running on the server hosting my wiki:
#!/bin/bash
status=$(curl -o /dev/null -Isw '%{http_code}\n' https://gameofroles.wiki/view/Accueil)
if [ "$status" -eq "200" ]; then
curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXXX
echo "Wiki up"
else
curl --retry 3 https://hc-ping.com/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXXX/$status
echo "Wiki down: $status"
fi
In short, I retrieve first the HTTP return status of the homepage. If it is 200, then all is good. Else I ping my job with the failing return status.
Then this script is executed daily with a cron defined like that:
0 0 * * * /wiki/healthcheck.sh
From now on, if my website is down, I will receive an automated email from healthchecks.io notifying me about the situation!

Note that in the case my server is fully down, which means both my wiki and my health check are not going to be able to run, the website healthchecks.io will automatically throw me a notification email too after a day and 1 hour. Because they expect a regular daily ping. The period and grace time before considering a job is failing are configurable.

Photo by Hush Naidoo on Unsplash