Set up free cron monitoring with healthchecks.io Matt B, April 17, 2024April 17, 2024 Table of Contents IntroWhat is cron monitoring?How does Healthchecks.io work?Setting up cron monitoringStep 1. Adding the check inside Healthchecks.ioStep 2. Editing the cronSetting up integrationsSelf-hosted vs SaaSWrapping upIntroWe recently covered how to setup free site monitoring using StatusCake, but what can you do if you want to setup free cron monitoring? Fortunately, there is an offering from healthchecks.io that allows you to do just that. This guide will show you how to configure this.What is cron monitoring?To understand what cron monitoring is, you first need to understand what a cron job is. If you’re reading this guide, there is a good chance that you already know what a cron job is, however if you don’t, here’s a simple explanation: a cron job is a task that runs on a server at a set interval. For instance, you might have a cron job that exports orders from an e-commerce shop every hour, on the hour.Cron monitoring is the setting up of systems to notify a site administrator if a cron job fails to run, or otherwise runs and errors. This can be useful as if you’ve got business critical crons, you will want to very quickly know if they fail so that you can troubleshoot them.How does Healthchecks.io work?Healthchecks.io is a great platform for monitoring cron jobs. It works like this:You set up a “check” within Healthchecks, which refers to a cron job. You configure this with how often it should be running.You edit an existing cron job so that it sends a request to a unique ping URL, generated by Healthchecks when you complete step 1.That’s it!Once you’ve completed the above steps, Healthchecks will listen to your crons. If they receive pings at the expected intervals, all is well. However, if a cron fails to ping the URL, Healthchecks will then notify you, via whichever integration channel you set up.Setting up cron monitoringThis guide will run through the process of setting up a cron monitor. As discussed in a previous guide, this site uses Updraft to back itself up each morning. We will use this cron as our example.Step 1. Adding the check inside Healthchecks.ioHaving made a free account, I now have one existing project which corresponds to my domain name. I can now add a new check from the admin interface, at which point I am prompted to confirm some settings:Below is an explanation of each setting:Name: This is the name of my check. This is an internal use label only.Slug: This refers to the permalink for the check. In my case, I’m going to leave this as suggested.Tags: Tags are used to categorize your cron checks, which is useful if you are monitoring several crons.Schedule: This is how frequently you expect your cron to ping the check endpoint. You can either format this as a cron expression or in plain English.Grace Time: This is how long to wait before sending an alert if a scheduled ping is not received. This is used to prevent excessive notifications if, for example, you have a cron that runs every minute and it’s late by one minute.Once you have created your health check, you should get a unique ping URL that looks like the one below:https://hc-ping.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxNote this down, as we will need to add this to our cron.Step 2. Editing the cronAssuming your server supports curl, you can easily get your cron to ping the request URL by appending the below to your task, where the URL is replaced with your unique one:&& curl https://hc-ping.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxFor example, my cron job was previously:wget -q -O - https://www.systemspro.net/backup-script.phpand it is now:wget -q -O - https://www.systemspro.net/backup-script.php && curl https://hc-ping.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxNow, when my cron runs, it will ping the unique URL given to me by Healthchecks, confirming to Healthchecks that my cron job is running on schedule. If it’s more than 3 hours late (as this is the grace period I specified earlier), I’ll be notified via my integrations.We can also check that Healthchecks is receiving the pings correctly by visiting the URL manually. Having done so, I can now see a ping was received when I am viewing my check within Healthchecks:Setting up integrationsIn order for this to be useful, we need to have Healthchecks alert us if the cron is not running. This is where integrations come in. Simply put, an integration is a channel via which you are notified if a check fails. Healthchecks comes with a number of different integrations such as Slack, Email, Webhooks and more. In our example, we will configure email notifications.Head over to Healthchecks Dashboard -> (The project) -> (The check) -> Integrations, and select the integration you want to add.Each integration then has a simple interface for configuring it. In our example, we are adding email notifications, and we want to be alerted both when a cron stops working, and when it recovers.Save your changes, and just like that your cron monitoring is now fully setup! It’s advisable to give your integration a test using the “Test” button, as some of them require verification before being usable, such as the email integration.Self-hosted vs SaaSIt’s worth noting that alongside being available as a SaaS app, Healthchecks can also be self-hosted (even with Docker), allowing you greater control over your cron monitoring. Guides for this can be found on their GitHub repository. A paid version of Healthchecks is also available, giving you more monitors and other features.Wrapping upThis guide has shown you how to configure free cron monitoring using healthchecks.io. If you’ve got any questions or run into any problems, please feel free to leave a comment. DevOps