High Desert Hacker

Uptime Monitoring with HealthChecks.io

I use Healthchecks.io to monitor various servers in my home network. The free Hobbyist level lets you monitor up to 20 jobs, and set up is not difficult. You just set up a bash cron script on your server to periodically ping the service. It integrates with my Pushover notification service, so I can receive alerts on my phone.

Setup

Create an account at Healthchecks.io.
Go to the checks area and choose Add Check. I use the Simple schedule and set the Period for 2 hours, Grace Time of 30 minutes. The Period is the expected time between pings from your server, and the Grace Time is how long HealthChecks.io waits after the Period expires before going into the notification state.
Once you save the Check, you get a ping url to use in your script.

Testing

Test the url with curl.

curl --retry 3  https://hc-ping.com/12345678-1234-1234-9876-abcd3456jklm

 

You should see this ping show up in the Events listing for your Check on Healthchecks.io.

Create the Ping Script

Now to script this. Create a script file on the device/server to be monitored, with the following contents. Mine is called watchdog.sh. Set the URL value accordingly.

#!/bin/bash
# This script calls the healthcheck.io monitoring service. Tied to a cron.
URL="https://hc-ping.com/12345678-1234-1234-9876-abcd3456jklm"

curl --retry 3  $URL
exit 0

Add this script to cron.
sudo crontab -e

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
# healthchecks.io monitoring service
*/15  *  *  *  *    /mnt/nas/watchdog.sh > /dev/null

This one is set up to run every 15 minutes.

Integrations

I use Pushover as part of my Home Assistant environment. We’ll use this as example set up.
Choose Integrations, scroll to Pushover, and choose Add Integration. Configure and Save.

Now log into your Pushover account and you will see an authorization request from healthchecks.io. Choose your device to subscribe to (e.g. your mobile phone), alert sound, then click Subscribe Me.

Your integration is now set up.

Operation

When your server fails to run the script within the time constraints defined by your check, you will get an email notification as well as notification through any third party integrations you set up.

You can also simulate a failure by appending fail to the url

curl --retry 3  https://hc-ping.com/12345678-1234-1234-9876-abcd3456jklm/fail