# traffic.dliu.com health checks

<!-- Generated by scripts/health-docs.js from config/health.json; the same content as https://traffic.dliu.com/docs#health. -->

Every 15 minutes status.dliu.com visits this site as a guest, without signing in, from Ireland, Virginia and Tokyo. It opens the public pages, asks the site to check its own storage and scheduled jobs, then marks each function as working, slow or not working. It also checks the home page and /health from mainland China every hour, through Globalping probes.

- Human version: https://traffic.dliu.com/docs#health (the Health tab)
- Live status: https://status.dliu.com/site/traffic
- Contract: every dliu.com site follows the health contract of status.dliu.com (https://status.dliu.com/docs).

## Functions

The site is **down** when a critical function fails, and **degraded** when any other function fails.

| Key | Name | Critical | What is checked | If it is down |
| --- | --- | --- | --- | --- |
| `pages` | Pages | yes | You can open the dashboard and the docs. | The site doesn't open. |
| `public-stats` | Public statistics | no | The 7, 30 and 90-day visit numbers guests see are updated every day. | The numbers are stuck on an old day. |
| `page-script` | Page script | no | The small script every site loads downloads, so time on page and clicks are recorded. | The sites stop recording time on page and clicks; visitors themselves notice nothing. |
| `signin` | Microsoft sign-in | no | Sign in takes you to Microsoft, and private data stays locked until you do. | The owner can't sign in to see the full dashboard; guests notice nothing. |
| `logging` | Request logging | yes | Every visit to every site is recorded as it happens. | New visits stop being recorded and the dashboard stands still. |
| `bot-check` | Bot check | no | Bots are recognised, so they aren't counted as people. | Bots get counted as people, so visitor numbers run high. |

## Guest checks

Send each request as a guest: method `GET` (`HEAD` also works), no cookies, no `Authorization` header, user agent
`dliu-status-bot/1.0 (+https://status.dliu.com/docs)`, and do not follow redirects. A check passes when the status code matches, the `Content-Type` starts
with the given type, and the expectation holds. Slower than "Slow after" counts as slow (degraded).

| Function | Method | URL | Status | Content type | Expect | Slow after |
| --- | --- | --- | --- | --- | --- | --- |
| `pages` | GET | https://traffic.dliu.com/ | 200 | `text/html` | body contains "dl-header" | 2000 ms |
| `pages` | GET | https://traffic.dliu.com/docs | 200 | `text/html` | body contains "id="health"" | 2000 ms |
| `pages` | GET | https://traffic.dliu.com/docs/health | 301 | — | Location starts with /docs#health | 2000 ms |
| `pages` | GET | https://traffic.dliu.com/docs/health.md | 200 | `text/markdown` | body contains "# traffic.dliu.com health checks" | 2000 ms |
| `public-stats` | GET | https://traffic.dliu.com/stats/7d.json | 200 | `application/json` | JSON with key "generated" | 2000 ms |
| `page-script` | GET | https://traffic.dliu.com/t/s.js | 200 | `application/javascript` | body contains "__dlTraffic" | 2000 ms |
| `signin` | GET | https://traffic.dliu.com/auth/login | 302 | — | Location starts with https://login.microsoftonline.com/ | 3000 ms |
| `signin` | GET | https://traffic.dliu.com/api/me | 401 | `application/json` | JSON with key "error" | 3000 ms |

## Health endpoint

- URL: `GET https://traffic.dliu.com/health` (`HEAD` also works). Outside `/api/`; no sign-in.
- CloudFront's `/health` behavior forwards no cookies, no `Authorization` header and no query string to the origin,
  and the handler (lambda/dashboard/health.js) reads none of them.
- Cached for 60 s at CloudFront (cache policy keyed on nothing; the response says `cache-control: public, max-age=60`),
  so the checks run at most about once a minute however often `/health` is requested.
- Read only: one cheap read per dependency, no writes, no S3 LIST, no Athena query and no AbuseIPDB call.
- Each check has its own 2 s timeout; the whole response returns within 5 s.
- `Content-Type: application/health+json`. HTTP `200` when `status` is `pass` or `warn`, `503` when it is `fail`.
  The top-level `status` is the worst of the functions'.
- `output` appears only when a function is not `pass`, and is a short generic reason: `timeout`, `read failed`,
  `stale`, `last run failed` or `no recent logs`. No names, counts or user data are returned.

Example:

```json
{
  "status": "pass",
  "time": "2026-11-03T23:00:00Z",
  "functions": [
    {
      "key": "public-stats",
      "name": "Public statistics",
      "status": "pass"
    },
    {
      "key": "signin",
      "name": "Microsoft sign-in",
      "status": "pass"
    },
    {
      "key": "logging",
      "name": "Request logging",
      "status": "pass"
    },
    {
      "key": "bot-check",
      "name": "Bot check",
      "status": "pass"
    }
  ]
}
```

| Key | Name | What it reads | pass | warn | fail |
| --- | --- | --- | --- | --- | --- |
| `public-stats` | Public statistics | When stats/7d.json was last written (S3 HeadObject) | Within 26 hours | 26–50 hours | Older than 50 hours, or the read fails |
| `signin` | Microsoft sign-in | The sign-in settings (SSM GetParameters, the same read sign-in does, cached 5 minutes) | The read succeeds | — | The read fails or times out |
| `logging` | Request logging | How often the log partitioner ran in the last 3 hours (CloudWatch GetMetricStatistics, one metric) | At least once | — | Not at all, or the read fails |
| `bot-check` | Bot check | The last run's status, bots/status.json (S3 GetObject, one small file), and when hosting/asns.json was last written (S3 HeadObject) | Finished within 7 hours, and the list is under 8 days old | 7–25 hours, or the last run failed, or the list is older | Older than 25 hours, or the read fails |

The `pages` and `page-script` functions have no `/health` entry; the guest checks above cover them.

## Not tested

- The signed-in dashboard: the Athena queries behind every widget are for the owner only.
- The Check bots now button and the AbuseIPDB reputation lookups (they need a sign-in, and AbuseIPDB's free allowance is limited).
- The page script's reports to /t/e: a test report would count as a real visit.
- Completing the sign-in at Microsoft (it needs an assigned account).
- The daily log merge and the monthly city database download are seen only indirectly: when they break, Public statistics or Bot check go stale.

## Rules

- The tests are read only and must never change content: `GET` or `HEAD` only.
- Never send `POST` to `/t/e` (it would be recorded as a visit) or to `/api/`.
- traffic.dliu.com drops requests whose user agent starts with `dliu-status-bot/` or `globalping probe` (the
  hourly checks from mainland China through Globalping) from its logs, so the tests never count as traffic.
