Heartbeat monitoring
Set up a heartbeat
- In the app, choose Add monitor → Heartbeat.
- Set Expect a ping every to how often the job runs (1 minute to 7 days), and a grace period for how late it may be (up to 24 hours).
- Copy the monitor's ping URL. It looks like
https://spotdowntime.com/api/v1/ping/YOUR_TOKEN. - Call it at the end of the job, only when the job succeeded.
How a heartbeat decides it's down
Each ping sets a deadline: now + interval + grace period. If the next ping hasn't arrived by then, the monitor goes down, an incident opens and your alert channels are notified. The next ping brings it back up and sends a recovery alert.
The first deadline starts when you create the monitor, so a job that never runs is caught too. Pings to a paused monitor are ignored. A successful ping within 10 seconds of the previous one is ignored, so retries in your job don't pile up.
Ping URL reference
| Request | Effect |
|---|---|
GET /api/v1/ping/TOKEN | The job ran. Marks the monitor up and resets the deadline. |
POST /api/v1/ping/TOKEN | Same as GET. Any request body is ignored. |
HEAD /api/v1/ping/TOKEN | Same as GET, for tools that can only send HEAD. |
GET or POST …/TOKEN/fail | The job failed. Marks the monitor down right away and alerts, without waiting for the deadline. |
GET or POST …/TOKEN/start | The job started a run. Changes nothing on its own; the next ping measures how long the run took (see Run time). |
A successful call answers 200 with {"ok":true}. An unknown token answers 404. No login or API key is needed.
Run time
A missing ping catches a job that didn't run, but not one that ran far longer than usual and still finished. To catch that, ping /start when the job begins. The next ping (success or /fail) then records how long the run took, and the monitor's chart shows run durations. Two optional limits, set when you edit the monitor, judge each run:
| Setting | What it does |
|---|---|
| Maximum run time | A run still going past it goes down right away, without waiting for the deadline, since it has probably hung. One that finishes over it sends a warning. |
| Warn when a run takes | Sends a warning when a run takes that many times its usual length, the median of the last 10 runs. It starts after 5 timed runs. |
A long run that finishes is a warning, like a slow website: it goes to your alert channels (not by text or call), doesn't count as downtime, and a later run back under the limits sends an all-clear. Failed runs aren't judged on their length. If a /start is never followed by a ping, it's forgotten after 7 days.
0 2 * * * curl -fsS -m 10 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN/start && /opt/backup.sh && curl -fsS -m 10 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN || curl -fsS -m 10 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN/failExamples
Shell script. -f makes curl fail on HTTP errors, -m 10 stops a slow network from hanging the job, and --retry 3 covers a brief blip:
#!/bin/sh
set -e
/opt/backup.sh
curl -fsS -m 10 --retry 3 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN > /dev/nullCrontab. && pings only if the job succeeded; || reports a failure instead:
0 2 * * * /opt/backup.sh && curl -fsS -m 10 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN || curl -fsS -m 10 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN/failGitHub Actions. Store the URL as a repository secret named HEARTBEAT_URL:
- name: Report to Spot Downtime
if: always()
run: |
if [ "${{ job.status }}" = "success" ]; then
curl -fsS -m 10 --retry 3 "$HEARTBEAT_URL"
else
curl -fsS -m 10 --retry 3 "$HEARTBEAT_URL/fail"
fi
env:
HEARTBEAT_URL: ${{ secrets.HEARTBEAT_URL }}Kubernetes CronJob.
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-report
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: report
image: your-image
command: ["/bin/sh", "-c", "run-report && curl -fsS -m 10 $HEARTBEAT_URL"]
env:
- name: HEARTBEAT_URL
valueFrom:
secretKeyRef: { name: heartbeat, key: url }Python.
import urllib.request
def heartbeat(ok: bool = True) -> None:
url = "https://spotdowntime.com/api/v1/ping/YOUR_TOKEN" + ("" if ok else "/fail")
try:
urllib.request.urlopen(url, timeout=10)
except OSError:
pass # never let monitoring break the job itselfNode.js.
await fetch("https://spotdowntime.com/api/v1/ping/YOUR_TOKEN", { signal: AbortSignal.timeout(10_000) }).catch(() => {});Choosing the interval and grace period
Set the interval to the job's schedule, and the grace period to its longest normal run time plus a margin. A nightly backup that usually takes 20 minutes: interval 1 day, grace 1 hour. A queue worker that pings every minute: interval 1 minute, grace 2 minutes.
Too short a grace period gives false alarms when a job runs long; too long delays real alerts. The monitor's page shows every ping, so you can see how punctual the job really is and adjust.
Next steps
Send the alerts somewhere your team will see them: Slack, Teams, email or your own system with webhooks.
Something missing or unclear? Tell us.