Monitors

Heartbeats for cron jobs and scheduled tasks

A heartbeat watches a job that runs by itself. The job calls a secret address when it has finished. If the call does not come in time, or the job says that it failed, you get an alert.

On this page

Create a heartbeat

  1. On Heartbeats, press New heartbeat.
  2. Give it a Name, such as Nightly backup.
  3. Under How the job runs, choose Fixed period or Cron schedule, and fill it in. The section on timing below explains both.
  4. Choose the Grace time: how late a report may be before you are told.
  5. Press Create heartbeat. The heartbeat's page opens, with its address.

Until the job reports for the first time, the heartbeat shows Waiting for first report. Nothing is expected before that, so a new heartbeat is never late.

Members, admins and owners create heartbeats and see their addresses. Viewers see the heartbeats, but not the addresses. How many heartbeats you can have depends on your plan: see the pricing page.

Call the address from your job

Under Address, the heartbeat's page shows its address, such as https://app.uptimezy.com/api/v1/ping/<token>. The token is 32 random letters, digits, - and _. Keep the address secret: anyone who has it can report for the job.

The page also shows these commands, ready to copy with your address in them. At the end of the job:

Shell
curl -fsS -m 10 --retry 3 https://app.uptimezy.com/api/v1/ping/<token>

In a crontab, after the job. With &&, the address is called only when the job ends without an error:

crontab
0 3 * * * /path/to/job.sh && curl -fsS -m 10 --retry 3 https://app.uptimezy.com/api/v1/ping/<token>
  • GET, POST and HEAD all work. Any HTTP client will do, such as wget -q -O /dev/null https://app.uptimezy.com/api/v1/ping/<token>.
  • The answer is 200 with {"status":"ok"}, or {"status":"paused"} when the heartbeat is paused and the report was thrown away.
  • An address that does not exist gets 404.
  • One address takes up to 30 reports a minute. More get 429, with Retry-After: 30.

New address gives the heartbeat a new address. The old one stops working at once, so change it in your jobs too.

Report a start, a failure and the output

AddressWhat the job says
…/ping/<token>It finished well. The heartbeat is Up, and an open incident ends.
…/ping/<token>/startIt started. The report of success must now come within the grace time, or the heartbeat is late. This catches a job that hangs.
…/ping/<token>/failIt failed. The heartbeat is Down at once, and you get an alert without waiting.

The heartbeat's page shows this example:

Shell
curl -fsS -m 10 --retry 3 https://app.uptimezy.com/api/v1/ping/<token>/start
/path/to/job.sh > job.log 2>&1 || curl -fsS -m 10 --retry 3 --data-binary @job.log https://app.uptimezy.com/api/v1/ping/<token>/fail

That example reports the start and a failure. When you use /start, also call the address itself when the job succeeds, or the job counts as hanging when the grace time is over. A whole script:

Shell
#!/bin/sh
URL=https://app.uptimezy.com/api/v1/ping/<token>

curl -fsS -m 10 --retry 3 "$URL/start"
if /path/to/job.sh > /tmp/job.log 2>&1; then
  curl -fsS -m 10 --retry 3 --data-binary @/tmp/job.log "$URL"
else
  curl -fsS -m 10 --retry 3 --data-binary @/tmp/job.log "$URL/fail"
fi

Send what the job printed

  • Send the output in the body of a POST, as curl --data-binary @job.log does. It is read as plain text, whatever its type.
  • The first 10,000 characters are kept and shown on the heartbeat's page, under Last output.
  • Each report of success or failure replaces the last output. A call without a body leaves it empty.
  • A body sent to /start is not kept.

Fixed period or cron schedule

Fixed period

Period is how often the job runs: from 1 minute to 30 days in the dashboard. After each report, the next one is expected within the period plus the grace time, counted from the report.

Cron schedule

Cron schedule takes the same five parts as your crontab line: minute, hour, day of month, month and day of week. Then choose the Time zone: the times of the schedule are in that zone, and daylight saving time is followed. While you type, the form shows the next runs as we read them.

ScheduleWhen it runs
0 3 * * *Every day at 3:00
0 * * * *Every hour
0 9 * * 1-5Weekdays at 9:00
*/15 * * * *Every 15 minutes
0 0 1 * *First day of the month
30 2 * * sunEvery Sunday at 2:30
0 */6 * * *Every 6 hours: at 0:00, 6:00, 12:00 and 18:00
0 8,20 * * *Every day at 8:00 and 20:00
@dailyEvery day at 0:00, the same as 0 0 * * *
  • Each part takes *, a number, a range such as 1-5, a list such as 1,15, and steps such as */10 or 0-30/10.
  • Months can be written jan to dec and days sun to sat. Sunday is 0 or 7.
  • These names work too: @yearly, @annually, @monthly, @weekly, @daily, @midnight and @hourly.
  • When both the day of month and the day of week are set, a day that matches either one counts, as in cron.

With a schedule, the report is due at the next run after the last report, plus the grace time. A report up to a minute before a run counts for that run. For example, with 0 3 * * * and 1 hour of grace, a job that reports at 3:05 is next expected by 4:00 tomorrow.

Choose the grace time

Grace time is how long a report may be late before you are told: from 1 minute to 1 day in the dashboard. At first it is 1 hour.

With /start, the report of success must come within the grace time after the start. So the grace time is also the longest your job may run.

More ways to call the address

In a crontab, keep what the job printed and send it with the report, or report the failure:

crontab
0 3 * * * /path/to/job.sh > /tmp/job.log 2>&1 && curl -fsS -m 10 --retry 3 --data-binary @/tmp/job.log https://app.uptimezy.com/api/v1/ping/<token> || curl -fsS -m 10 --retry 3 --data-binary @/tmp/job.log https://app.uptimezy.com/api/v1/ping/<token>/fail

With wget instead of curl:

Shell
wget -q -O /dev/null https://app.uptimezy.com/api/v1/ping/<token>

A job started by a systemd timer: in its service, ExecStartPost= runs only when ExecStart= succeeded.

systemd
[Service]
Type=oneshot
ExecStart=/path/to/job.sh
ExecStartPost=/usr/bin/curl -fsS -m 10 --retry 3 https://app.uptimezy.com/api/v1/ping/<token>

Late, failed and back

StateWhat it means
Waiting for first reportNo report yet. Nothing is expected.
UpThe last report came in time.
DownLate: No report in time. Or the job reported a failure: The job reported a failure.
PausedReports are thrown away and nothing is expected.

We look for late heartbeats every 15 seconds. When the due time has passed without a report, the heartbeat is down, an incident opens from the due time, and the alert goes to the same email, chat apps and webhooks as for monitors. The next report of success ends the incident and tells you that the job reports again.

Pause ends an open incident without a message. Resume starts fresh: the heartbeat waits for the next report.

More guides

All guides