# Device health

Calls go to https://supply.coronium.ai, signed in as in [enrolment](/guides/device-enrol.md). The states that decide whether a device may carry buyers at all are in [device states](/guides/device-states.md).

## What it is

Coronium checks that each connected device still carries traffic. A device that is `online` and `admitted` or `established` reads `health` in `GET /app/api/devices`; any other device reads `health` as null.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
curl -sS -b coronium.cookies "$SUPPLY/app/api/devices" | jq -c '.counts.byHealth, (.devices[] | {deviceId, status, health})'
```

Expect: `health.state`, `health.reason` for a failing device, `health.since` for when the state began and `health.firstByteMs` for how quickly the first byte of the last passed check came back. `counts.byHealth` counts those devices by state. Safe to repeat: yes.

<!-- facts:begin health.states -->
| `health` reads | Means | Do |
|---|---|---|
| `unchecked` | Connected. Its first check is on its way. | Nothing. |
| `healthy` | Passed its last check. | Nothing. |
| `slow` | Passes its checks, but slowly. It may be used after faster devices. | Check the line, or move the device closer to its router. |
| `failing`, `silent` | Connected, but it does not answer. | Restart the agent and read its log. |
| `failing`, `no_bytes` | It opens connections and returns no data. | Look for a firewall, a VPN or a sign-in page on this network. |
| `failing`, `tls_failed` | Something on this network alters secure connections. | Remove the inspecting proxy or antivirus, or use another network. |
| `failing`, `no_route` | It cannot reach the internet. | Check the connection and its DNS. |
<!-- facts:end health.states -->

A failing device gets no new buyer traffic, keeps the traffic it carries, and is checked again by itself: nobody has to act for it to come back. A device that connects is checked at once, with two bounds: one that reconnects again and again is not checked for it each time, and one that fails and reconnects sooner than its next check was due waits for that check. A reconnect too quick for the directory to show is not seen as a new connection, so such a device waits for its scheduled check. An account is told once a day of devices that stay failing, by the `device_withheld` [notification](/guides/notifications.md).

## What the checks cost

<!-- facts:begin health.checks -->
A check is one short secure connection through the device to Coronium's own servers. It uses the device's connection, earns nothing and is in no count of `requests`, `bytesUp` or `bytesDown`. A connected device on a home line that carries no traffic is checked about every 20 minutes. A device on a mobile exit, or one that carries traffic, is checked about every 60 minutes. One check is ended once it has moved 8192 bytes of payload both ways together, as the edge counts them. No check of a device starts once its checks have moved 1048576 bytes of payload in a UTC day, as the edge counts them. The device's line also carries what the edge does not count: the connection's own framing and the name lookup. A device that just connected or failed a check is checked sooner.
<!-- facts:end health.checks -->
