# Metrics

A monitoring system can collect the state of the wall: *Settings > Metrics* makes a token, and
from then on `GET /metrics` answers whoever sends it, in the text format that Prometheus and
everything that reads its format understand:

```
scrape_configs:
  - job_name: qkvm
    metrics_path: /metrics
    authorization:
      credentials: qkvm_...            # the token, as shown once when it was made
    static_configs:
      - targets: ["192.168.1.20:8787"]
```

qKVM answers when it is called by an IP address, by a name without a dot, or by one ending in
`.local`, `.lan`, `.internal`, `.home.arpa` or `.ts.net`. Any other name the collector is to
reach it by has to be listed under `allowed_hosts`, as for a browser; use the
[offline server settings command](https://qkvm.com/docs/advanced-server-settings).

| Metric | Says |
|---|---|
| `qkvm_devices{state}` | how many tiles are in each state: `online`, `no_signal`, `offline`, `auth`, `error`, `busy`, `connecting` |
| `qkvm_device_up{id,device,kind,group}` | 1 while that device answers, 0 while it does not |
| `qkvm_device_picture{...}` | 1 while it shows a picture; for a server, while it is switched on |
| `qkvm_device_last_seen_seconds{...}` | seconds since it last answered |
| `qkvm_device_temperature_celsius{...,sensor}` | how warm it is: the KVM itself (`sensor="device"`), or each sensor of a server |
| `qkvm_server_healthy{...}` | 1 while a server's management controller calls it healthy |
| `qkvm_unlocked` | 1 while qKVM can talk to its devices (somebody has signed in since it started) |
| `qkvm_sessions`, `qkvm_devices_configured`, `qkvm_update_available`, `qkvm_info{version}`, `qkvm_start_time_seconds` | about qKVM itself |

- The token is shown once and qKVM keeps only its hash. It lets its holder read the above and
  nothing else; a new one replaces it, and *Switch off* makes `/metrics` answer nobody.
- While metrics are on, qKVM goes on watching the devices after the last person has signed
  out, as it does for alerts: the saved device passwords stay usable in memory for that.
- After a restart qKVM goes on by itself. Started with `--locked-start` (see
  [Keeping it running](https://qkvm.com/docs/keeping-it-running)), nothing can be collected about the devices
  until somebody signs in; `qkvm_unlocked` is 0 until then, which is worth an alert of its own.
- A collector is nobody watching: a JetKVM that is not on screen is only asked whether it
  answers, as for alerts, and its one viewer is left to whoever wants it.
- `GET /healthz` is separate and needs no token. It says that qKVM is running, which version,
  and whether it is still waiting for a sign-in after a restart (`"locked"`).
