Build Better Stack

YESreplaces $34/mosaves $408/yrback to the verdict

0%0 of 22 items done

Saved on this device only. Tick prerequisites first, then work the phases in order · do not start one until the checks above it pass.

An uptime monitor you run yourself: a fetch on an interval with a real timeout, a state machine that only calls a site down after two consecutive failures, one chat message on down and one on recovery, and a public status page with uptime percentages, a latency sparkline and an RSS feed of incidents. Honest about the one thing a single box cannot do: tell your outage from your own network's.

estimated effort one sittingthe files for this build are in the project pack

RuntimeNode 22 with node:http, node:sqlite and global fetchDatabaseSQLite in WAL modeAlertsOne chat webhookHostingA VPS on a different provider than the sites it watches

Before step 1

Everything below is assumed from the first step. Tick each one when you actually have it, not when you plan to.

  1. installfree

    Why Everything in this build runs on it: the server, the scripts, the tests.

    Get it Download the LTS installer from nodejs.org, or install with your package manager (brew install node, or nvm install 22). Restart the terminal afterwards. open ↗

    Verify node --version prints v22 or higher

  2. installfree

    Why Every step below is a command you type or a file you edit.

    Get it VS Code (code.visualstudio.com), Cursor or Zed. Open a folder for the project and use the editor's built-in terminal. open ↗

    Verify You can open a folder and run a command in its terminal

  3. installfree

    Why History for your code, and the way most hosts deploy.

    Get it Install from git-scm.com or with your package manager, then run git init in the project folder once it exists. open ↗

    Verify git --version prints a version

  4. API keyfree

    Why Alerts go to a chat channel you already watch. A webhook URL is the only credential this needs.

    Get it Discord: Server settings > Integrations > Webhooks > New Webhook, copy the URL. Slack: create an app at api.slack.com/apps, enable Incoming Webhooks, add to a channel, copy the URL. Telegram: create a bot with @BotFather and use the bot token plus your chat id. open ↗

    Verify curl -X POST -H 'Content-Type: application/json' -d '{"content":"test"}' <url> posts a message (Discord form; Slack uses a text field)

  5. have readyfree

    Why Each monitor needs a URL, an interval, an expected status and optionally a keyword the body must contain.

    Get it List every site or endpoint. For each decide: check every 60 seconds or 300, expect 200, and a word that only appears when the page really works.

  6. about $5 a month

    Why A monitor hosted next to what it watches reports nothing when that host dies. Different provider, ideally a different region.

    Get it Hetzner if your sites are elsewhere, or vice versa. Smallest Ubuntu 24.04 instance with SSH. open ↗

  7. roughly $10 a year, or free on an existing domain

    Why A status page address you can give people, e.g. status.yourdomain.com.

    Get it Register at Cloudflare Registrar, Porkbun or Namecheap, or use a subdomain of one you already own. You add one DNS record in the deploy phase. open ↗

  8. installfree

    Why Automatic HTTPS in front of the Node process. Without TLS the browser features this relies on (and your visitors' trust) do not work.

    Get it On the VPS: follow the install steps at caddyserver.com/docs/install for Ubuntu. One Caddyfile with your domain and a reverse_proxy line is the whole config. open ↗

    Verify caddy version prints a version on the server

Data model

Create these before the first phase that stores anything. Changing a table later is the expensive kind of change.

- `monitors`: id, name, url, method, interval_seconds, timeout_ms,
  expected_status, keyword (nullable), enabled, status ('unknown' | 'up' |
  'down'), consecutive_failures, last_checked_at, last_change_at
- `checks`: id, monitor_id, checked_at, ok (bool), status_code, latency_ms, error
- `incidents`: id, monitor_id, started_at, ended_at, cause

Index `checks(monitor_id, checked_at)`. All timestamps are UTC epoch
milliseconds. `incidents` is a separate table from `checks` on purpose: uptime
percentage comes from checks, but the human question ("how long was it down, and
why") comes from incidents, and deriving that from raw checks at read time gets
slow and wrong at the edges.

Environment variables

These go in a .env file the app reads at startup. The pack's .env.example is this table as a file · copy it, never commit the filled-in version.

VariableNeededExampleWhere the value comes from
PORTrequired3000Any free port; Caddy proxies to it.
DATABASE_PATHrequired./data/uptime.dbSQLite file.
ALERT_WEBHOOK_URLsecretrequiredhttps://hooks.slack.com/services/...The chat webhook from the prerequisites.
ALERT_FORMATrequiredslackdiscord, slack or telegram.
FAILURES_BEFORE_DOWNoptional2Consecutive failures before a monitor is called down.
RETENTION_DAYSoptional90Days of raw checks to keep. Incidents are kept forever.
SITE_URLrequiredhttps://status.yourdomain.comPublic base URL for the status page and RSS feed.
ADMIN_USERrequiredadminAny username for the basic-auth admin pages.
ADMIN_PASSsecretrequiredchange-me-to-a-long-random-stringGenerate one: openssl rand -base64 24. Never reuse a real password.

The build, in order

  1. The check

    One function from a monitor to a result, with a timeout that actually fires and distinct error kinds.

    1. monitors (id, name, url, interval_seconds, timeout_ms, expected_status, keyword, enabled, status, consecutive_failures, last_checked_at, last_change_at), checks (id, monitor_id, checked_at, ok, status_code, latency_ms, error), incidents (id, monitor_id, started_at, ended_at, cause). Index checks(monitor_id, checked_at).

      Files server.mjsdb.mjscheck.mjs

      terminal
      mkdir uptime && cd uptime && git init && npm init -y && npm pkg set type=module
      mkdir data && cp .env.example .env
    2. fetch with an AbortController timeout, follow redirects, read at most 64 kB of body for the keyword, record latency. Return ok plus one of: dns, tls, timeout, status, keyword, as the error.

    3. terminal
      node scripts/check.mjs https://example.com 200 "Example Domain"
    done when · tick each as it passes
  2. Scheduler

    Each monitor on its own interval, concurrently with a cap, and one bad monitor never stops the loop.

    1. Every 5 seconds find monitors due (last_checked_at plus interval before now), run up to 10 concurrently, catch every exception per monitor. On boot treat every monitor as due.

    done when · tick each as it passes
  3. Transitions and incidents

    Down only after N consecutive failures, up on the first success, one incident per outage.

    1. Increment consecutive_failures on a failed check; at FAILURES_BEFORE_DOWN flip to down. Any success resets the counter and flips to up.

    2. Open a row on the flip to down with the first failure's error as cause; set ended_at on recovery. Incidents, not checks, are what people read later.

    done when · tick each as it passes
  4. Alerting

    One message down, one up, retries that never stall the loop.

    1. Down: monitor name and the error. Three retries with backoff, then record the failure and move on.

    2. Duration comes from the incident row's started_at and ended_at.

    done when · tick each as it passes
  5. Status page

    A public page whose numbers can be argued with, and a feed people can subscribe to.

    1. One row per monitor: dot, state, uptime over 24 h, 7 d and 30 d with the denominator printed (over 2,880 checks), a latency sparkline as inline SVG, recent incidents with durations. Meta refresh every 30 seconds.

    2. Subscription without accounts.

    3. terminal
      node scripts/seed.mjs 90
    done when · tick each as it passes
  6. Retention and deploy

    Old checks pruned, incidents kept, live behind HTTPS on the other provider.

    1. README: the single-region caveat stated plainly, the instruction to host on a different provider than the things watched, and the RSS URL.

      Files deploy/uptime.serviceCaddyfileREADME.md

    done when · tick each as it passes
what this build does not replace
after v1, if you want it

Need the files? The project pack on the verdict page hands your agent the whole brief · more uptime.