Contents Lesson 10 of 16

10 min read · professional

Knowing it broke before someone tells you

By the end of this lesson you will have a scheduled workflow that reads your deployed health answer from outside every fifteen minutes, a message to you when it fails, and a heartbeat that tells you when the watch itself has stopped.

Your tool will break while you are not looking. The question is only whether you find out from a monitor or from opening it three weeks later and realising it has been dead the whole time.

Check the thing, not the process

A process can be running and serving errors. Check behaviour instead: hit /api/health from outside your infrastructure, on a schedule, and expect a specific response body rather than merely a 200.

From the previous unit, that endpoint reports the store and upstream separately and costs no quota — which is what makes it safe to call every few minutes.

Watch four things

Is it up? The health check, from outside.

Is it fresh? A cockpit serving hour-old prices during the session is not "down" and is broken. Include the age of the newest data in the health response and alert on it — this is the failure that monitoring most often misses, because everything is technically working. Give the alert the market calendar and the feed's delay first, though: outside the session an old timestamp is the correct answer, and on a fifteen-minute feed fifteen minutes is the floor even at ten in the morning. An alert that fires every Friday evening is one you will learn to ignore.

Is it within quota? calls_used against the limit. This is the wall arriving, and you want to see it approaching rather than at the moment it lands.

Is it erroring? A rate of 5xx, not individual ones.

The watchdog has to be somewhere else

A monitor running on the machine it watches tells you nothing when that machine is gone. It has to run somewhere independent — a scheduled job elsewhere, a free uptime service, anything that is not the thing being watched.

And the alert has to reach you somewhere you actually look. An email you check weekly is not monitoring; it is a diary.

The failure this lesson exists to prevent

The specific shape, and it is common: something breaks quietly, nothing tells you, and you notice weeks later.

The reason it is so common in personal projects is that a silent failure has no cost until the moment you need the tool — and that moment is exactly when you cannot afford to spend an evening on repairs. A watchdog converts a three-week outage into a ten-minute one, and it is a few lines plus a free service.

Watch the watchdog

A monitor that stops running looks exactly like everything being fine.

So make it report success, not only failure — a heartbeat you would notice the absence of. Most uptime services do this by design, which is a good reason to use one rather than write your own.

Try it now

Set up the external check, then stop your deployment and confirm you are told within minutes. Then stop the monitor and see whether you notice — that second experiment is the one that teaches the lesson.

The prompt

The watch runs on GitHub Actions, somewhere other than your host, and reports to Healthchecks.io, which tells you about a failure and about silence. Plan mode on, and paste:

Add .github/workflows/watch.yml, run every fifteen minutes and by
hand, with a five-minute job timeout. It fetches the deployed health
answer from the HEALTH_URL repository variable with a twenty-second
timeout, and passes only when ok is true and calls_used is under 80% of
daily_limit. On a pass, curl WATCH_HEARTBEAT_URL; on anything else,
curl WATCH_HEARTBEAT_URL/fail with a one-line reason as the body.
WATCH_HEARTBEAT_URL comes from secrets; when it is not set, print a
warning and send nothing. Explain why this spends no API calls before
writing it, and do not run it.

A good answer is one new file. The agent explains that the health route reads only the free user endpoint, so a check every fifteen minutes spends nothing. Freshness waits for your market calendar and your feed's delay; add it to the health answer once those are written down, not before.

Two costs it does not explain, so know them before you turn it on. GitHub bills each run as at least a minute, so 96 runs a day is about 2,900 Actions minutes a month: free on a public repository, and more than the free allowance on a private one. And on the free plan 80% of 20 is 16 calls, and the first load of a cockpit's default layout spends several of them (13 in our reference cockpit, 8 on a free key whose screen is refused, fewer in a leaner one), so on many days you use the tool the watch goes red for quota: that red is the wall arriving, not the tool breaking.

Check it yourself

GitHub runs a workflow by hand only once its file is on the default branch, so commit it first, then push it and merge it there:

git status          # .github/workflows/watch.yml, and no .env file
git add -A
git commit -m "Watch the deployed health answer from outside, with a heartbeat on the watch itself"
  1. On Healthchecks.io, create a check with a fifteen-minute period and a grace time of thirty minutes, then store its ping URL with gh secret set WATCH_HEARTBEAT_URL and your health URL with gh variable set HEALTH_URL.
  2. Run it by hand with gh workflow run watch.yml: the run is green and the check on Healthchecks.io turns up.
  3. Point HEALTH_URL at a path that does not exist and run the watch by hand: the run goes red, its fail ping marks the check down, and you are told without opening anything. Put it back.
  4. Disable the watch with gh workflow disable watch.yml and wait past the grace time: the heartbeat goes down and tells you. Enable it again.
Compare with ours
# .github/workflows/watch.yml
name: Watch
on:
  schedule: [{ cron: "*/15 * * * *" }]
  workflow_dispatch:
jobs:
  watch:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    env:
      HEALTH_URL: ${{ vars.HEALTH_URL }}
      HB: ${{ secrets.WATCH_HEARTBEAT_URL }}
    steps:
      - name: Health, from outside
        run: |
          body=$(curl -fsS -m 20 "$HEALTH_URL") || { echo "no 200 from $HEALTH_URL" > reason; exit 1; }
          echo "$body" | jq -e '.ok == true and (.daily_limit == null or .calls_used < .daily_limit * 0.8)' \
            || { echo "unhealthy: $body" > reason; exit 1; }
      - if: success()
        run: '[ -z "$HB" ] && echo "::warning::no heartbeat URL" || curl -fsS -m 10 "$HB"'
      - if: failure()
        run: '[ -z "$HB" ] && echo "::warning::no heartbeat URL" || curl -fsS -m 10 --data-binary @reason "$HB/fail"'

GitHub turns off a public repository's schedules after 60 days without activity, and a tool that works is a tool nobody commits to. The heartbeat is what notices. The full state at the end of this unit is on the starter's branch ref/ship-your-tool/u3.

Checkpoint

git status          # nothing to commit: the watch went in before the checks
git fetch origin
git log --oneline -1 origin/main -- .github/workflows/watch.yml   # your commit, merged

Then answer this lesson's questions.