Heartbeat checks

A heartbeat check monitors a job that runs on a schedule, such as a cron job, a backup or a queue worker. ZeroDrop does not probe anything for this type. Instead, your job sends a ping to a URL each time it runs. If no ping comes in time, or the job reports a failure, ZeroDrop opens an incident.

A heartbeat check uses no locations and no consensus. The other features work the same as for HTTP and SMTP checks: notification channels, incidents, repeat reminders, maintenance windows, uptime, objectives, badges and status pages.

Settings

Setting Default Notes
Name required A label for the check. It must be unique in your account.
Period required How often the job runs. The minimum is the minimum interval of your account (60 seconds by default). The maximum is 31 days, so a monthly job fits.
Grace time 5 minutes How late a ping can be before the check fires. The minimum is 60 seconds. The maximum is 7 days.
Uptime objective none The same as for the other check types. See Dashboards.
Public badges off Publish the status and uptime badges of this check. A heartbeat check has no SSL badge.

A heartbeat check counts towards the maximum number of checks of your account.

Period and grace time

After a successful ping, ZeroDrop expects the next successful ping within the period plus the grace time. The detail page of the check shows this time as Next ping due.

Set the period to the schedule of the job. Set the grace time to cover how long the job can run, plus some time for a slow start. For example, a backup starts at 03:00 every day and can run for 40 minutes. Set the period to 1 day and the grace time to 1 hour.

States

State Meaning
Waiting The check has had no ping yet. It does not alert.
Ok The last ping was a success, and the next ping is not late.
Firing A ping is late, or the job reported a failure. An incident is open.
Paused The check is off. ZeroDrop ignores its pings.

A new check waits until its first ping. You can therefore create the check before you deploy the job, and no false alert comes in the meantime.

ZeroDrop examines heartbeat checks one time each minute. An incident therefore opens up to one minute after the deadline, or after a failure ping. A success ping closes the incident within one minute.

Uptime starts at the first ping. Before that, the check shows no uptime value, and the uptime badge shows "no data". The uptime bars on the detail page and on status pages show "no data" for the days before the first ping.

Send pings

The console shows the ping URL one time, after you create the check. It looks like this:

https://zerodrop.app/api/v1/ping/zdp_<token>

Copy the URL before you close the dialog. ZeroDrop keeps only a hash of the token, so it cannot show the URL again. If you lose the URL, rotate the token (see below).

Request Meaning
POST <ping URL> The job succeeded.
POST <ping URL>/fail The job failed.

Send a POST request. A GET request gets the status 405 and does not count as a ping. Link previews, mail scanners and proxies send GET requests on their own, so a GET ping could hide a real outage.

The ping needs no API token. The token in the URL identifies the check, so keep the URL secret, like a password.

ZeroDrop does not read the request body. Your job can send its output in the body, but ZeroDrop does not keep it.

Responses

Status Meaning
200 ZeroDrop received the ping. A paused check also gets 200, but ZeroDrop does not record the ping.
404 No check has this token. The token was rotated, or the check was deleted.
405 The request was not a POST request.
429 Too many pings. Wait for the number of seconds in the Retry-After header, then send the ping again.

Use curl -fsS. With -f, curl exits with an error for a status of 400 or more. The job then fails in a way that you can see in its own logs.

Rate limits

Each token accepts a burst of 6 pings, then 1 ping every 10 seconds. Each client IP address has a separate, higher limit. A job that retries a ping a few times stays well below these limits.

A failure ping always alerts

A failure ping opens an incident at the next examination, also when a success ping comes before that time. For example, the job fails, and a retry of the job succeeds 10 seconds later. ZeroDrop then opens an incident for the failure and closes it one minute later. You therefore always learn that a run failed.

Examples

Replace <ping URL> with the URL of your check.

Crontab

0 3 * * * if /usr/local/bin/backup.sh; then curl -fsS -X POST <ping URL>; else curl -fsS -X POST <ping URL>/fail; fi

The failure ping depends only on the exit status of the job. If only the success ping fails, the job is not reported as failed.

systemd

Run the job as a service that a timer starts. Add these lines to the service unit:

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
ExecStartPost=-/usr/bin/curl -fsS -X POST <ping URL>
ExecStopPost=/bin/sh -c 'if [ "$SERVICE_RESULT" != "success" ]; then /usr/bin/curl -fsS -X POST <ping URL>/fail; fi'

systemd runs ExecStartPost only after ExecStart succeeds. It runs ExecStopPost in all cases, and $SERVICE_RESULT tells the two cases apart.

The - before the success ping is necessary. Without it, a failed success ping marks the service as failed, and ExecStopPost then sends a failure ping for a job that succeeded. A missed success ping still opens an incident when the deadline passes.

A script

#!/bin/sh
PING="<ping URL>"
if ./run-export; then
  curl -fsS -m 10 --retry 3 -X POST "$PING"
else
  curl -fsS -m 10 --retry 3 -X POST "$PING/fail"
fi

-m 10 stops a ping after 10 seconds. --retry 3 sends the ping again after a network error.

Rotate the token

On the detail page of the check, select Rotate token and confirm. ZeroDrop then shows the new ping URL one time. The old URL stops working at once, so the pings of your job get 404 until you give the job the new URL.

Rotate the token when the URL leaks, or when you lose it.

Pause and resume

To pause a check, send its settings with enabled set to false through the API. A paused check ignores its pings and does not alert. When you pause a check with an open incident, the incident closes. When you resume the check, it waits for a new first ping, the same as a new check.

Alerts for a heartbeat check

An alert for a heartbeat check gives the cause:

  • heartbeat late: no success ping came in time. The alert gives the time of the last successful ping and the deadline.
  • heartbeat failed: the job sent a failure ping. The alert gives the time of the failure.

A late check can also report a failure before it recovers. ZeroDrop then sends a second Fire alert for the same incident, with the cause heartbeat failed. See The webhook payload.