Chapter 11 · Lesson 10 of 10
Monitoring and logs

Build a public status page for your service

A public status page tells users whether your service works right now; host it separately from the service it reports on and update it from a check script or a self-hosted status tool.

By the end you will

Publish a static status page fed by a check script, hosted separately from your main server, with a way to post incident notes.

Time
30 min
Level
Intermediate
Check
4 questions
You need
  • A second host or static hosting for the page
  • The uptime check script from the earlier lesson

A public status page tells users whether your service works right now and what happened recently. The simple version is a static HTML page that reads a status.json file, which your check script rewrites every minute. Host it away from the server it reports on, show when the data was last checked, and write incident notes in plain, specific words.

How it works#

Your check script from uptime checks with a script and timer already knows if each component is up. Extend it so it writes a small JSON file after each run, and copy that file to a separate place that serves static files. The page loads status.json in the browser and shows one line per component. There is no database and no server code to attack. See what to monitor first for which components belong on it.

What the page shows: the current state of each user-facing part (website, API, login), the time of the last check, and a short list of recent incidents. Do not show internal metrics. Users want to know “is it me or you”, not CPU graphs.

Step 1: Host it separately#

Put the page where the outage cannot reach it: another VPS, a different provider or a static hosting service. If it lives on the server it reports on, it goes dark exactly when users look for it. A small nginx or Caddy on a second host is enough for a static page, as in nginx from scratch. Give it its own subdomain such as status.example.com, with HTTPS from automatic HTTPS with Caddy or certbot. Also think about what else the two share. If both depend on the same DNS provider, a DNS failure takes both down.

Step 2: Write status.json from the check script#

Add this to the end of the check script, using the result variable now from the earlier lesson:

bash
cat > /var/www/status/status.json.tmp <<JSON
{
  "checked_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
  "components": [
    {"name": "Website", "state": "$now"}
  ]
}
JSON
mv /var/www/status/status.json.tmp /var/www/status/status.json

Writing to a temporary file and renaming it means a visitor never reads a half-written file. Add one entry per component you check, and use the same logic for each URL. If the checker runs on a different machine from the page host, copy the file with scp or rsync over SSH using a limited key, as in copy files with scp and rsync.

Step 3: Write the page#

Create index.html next to status.json:

html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Service status</title>
</head>
<body>
  <h1>Service status</h1>
  <ul id="components"></ul>
  <p id="checked"></p>
  <script>
    fetch("status.json", { cache: "no-store" })
      .then((r) => r.json())
      .then((data) => {
        const list = document.getElementById("components");
        data.components.forEach((c) => {
          const li = document.createElement("li");
          li.textContent = c.name + ": " + (c.state === "up" ? "Operational" : "Problem");
          list.appendChild(li);
        });
        const age = (Date.now() - Date.parse(data.checked_at)) / 60000;
        document.getElementById("checked").textContent =
          "Last checked " + data.checked_at + (age > 5 ? " (data is stale)" : "");
      })
      .catch(() => {
        document.getElementById("checked").textContent = "Status data unavailable.";
      });
  </script>
</body>
</html>

The page flags data older than five minutes as stale. Without that, a dead checker would keep saying everything works. Add a section below it for incident notes, written by hand.

Step 4: Or use a self-hosted tool#

Tools such as Uptime Kuma and Gatus run checks and serve a status page themselves. They save you writing the page, but you now run and update another service, and it still must live on a different host from what it monitors. Read each project’s own documentation for features, installation and security advice before choosing. A script and a static file is fewer moving parts for a single service.

Step 5: Write incident notes#

When something breaks, add a note at the top within minutes, even if you know little:

output
Investigating: Some users cannot log in (since 10:05 UTC)
10:12 UTC: We have found a failing database connection and are working on it.
10:40 UTC: Resolved. Logins work again. A full explanation will follow.

Say what users see, when it started, what you know and when the next update comes. Do not blame others or guess at causes. After a big incident, add a short written summary of what happened and what you changed. Keep old incidents visible for a while, since hiding them looks like hiding problems. Decide in advance who may post, so nobody waits for permission during an outage. The alerts that tell you something is wrong come from alerting without alert fatigue.

Check it worked#

  • curl -s https://status.example.com/status.json returns fresh JSON with a recent checked_at.
  • Opening the page shows each component and the check time.
  • Stop the checker for ten minutes and confirm the page marks its data stale.
  • Break the monitored service briefly and see the line change to Problem within a few minutes.
  • The status host stays reachable when the main server is off.

Edge cases and gotchas#

  • Same failure domain. Hosting on the same provider, region or DNS as the service can fail together. Separate what you can.
  • Stale green. A page frozen on “Operational” is worse than no page. Always show the check time.
  • Over-sharing. Do not publish internal hostnames, versions or error messages that help an attacker.
  • Flapping state. Require two failed checks before showing a problem, or the page will blink on single dropped packets.
  • Overpromising wording. Phrases like “100 percent uptime” invite disputes. Report what happened.
  • Caching. If a CDN or browser caches status.json, visitors see old data. Serve it from the same origin as the page, with short cache headers.

Troubleshooting#

SymptomLikely causeFix
Page shows Status data unavailable.status.json missing or wrong pathCheck the file exists and is readable by the web server
SyntaxError: Unexpected token in the consoleMalformed JSON from the scriptValidate with python3 -m json.tool status.json
Page always shows old dataBrowser or CDN cacheUse cache: "no-store" and short cache headers
scp: Permission deniedKey or directory permissionsFix ownership and the authorized key, see log in with SSH keys
Page shows Operational during an outageChecker is dead or on the same hostMove the checker and show data age
403 Forbidden on status.jsonWeb server cannot read the fileFix permissions on the directory
Mixed content warningsPage on HTTPS fetches HTTPUse relative URLs and HTTPS everywhere
Component never turns redCheck tests the wrong URLTest a real page and its body

Quick reference#

bash
python3 -m json.tool /var/www/status/status.json
curl -s https://status.example.com/status.json
rsync -az status.json deploy@203.0.113.30:/var/www/status/

Related post: self-host a static site with Docker.

Next#

Continue to the delivery side with CI/CD pipeline stages explained.

Check what you learned4 questions
1Where should the status page be hosted?
2What does the check script write for the page to read?
3Which incident wording is best?
4The checker died but the page still says all systems operational. What is the fix?

Frequently asked questions

What should a status page show?

The current state of each user-facing component, such as website, API and login, plus a short list of recent incidents with times and plain explanations. Keep it simple and accurate.

Why host the status page somewhere else?

If it runs on the server it reports on, it goes down with it and tells users nothing when they need it most. Use a different host, provider or static hosting.

Do I need a tool like Uptime Kuma or Gatus?

No. A static page and a script can be enough for one service. Self-hosted tools such as Uptime Kuma and Gatus add checks and a ready-made page, at the cost of running and updating them.

How do I word an incident note?

State what users see, when it started, what you know and when you will update. Avoid blame and guesses, and mark it resolved with the time when it is fixed.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios