# Metrics

A monitoring system can collect the state of the wall from `GET /metrics`, in the text format that Prometheus and everything that reads it understand.

## Set it up

1. In *Settings > Metrics*, make a token. It is shown once.
2. Give it to the collector:

```
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"]
```

3. Alert on `qkvm_unlocked` being 0, as well as on the machines.

qKVM answers when it is called by an IP address, a name without a dot, or a name ending in `.local`, `.lan`, `.internal`, `.home.arpa` or `.ts.net`. Any other name must be listed under `allowed_hosts`: see [Advanced server settings](https://qkvm.com/docs/web/advanced-server-settings).

## What it says

| 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}` | the KVM's own temperature (`sensor="device"`), or each sensor of a server |
| `qkvm_server_healthy{...}` | 1 while a server's controller calls it healthy |
| `qkvm_unlocked` | 1 while qKVM can talk to its devices |
| `qkvm_sessions`, `qkvm_devices_configured`, `qkvm_update_available`, `qkvm_info{version}`, `qkvm_start_time_seconds` | about qKVM itself |

## Good to know

- The token reads the metrics and nothing else, and qKVM keeps only its hash. A new token replaces the old one; *Switch off* makes `/metrics` answer nobody.
- While metrics are on, qKVM keeps watching the devices after the last person has signed out.
- After a restart it carries on by itself. Started with `--locked-start`, nothing about the devices can be collected until somebody signs in, and `qkvm_unlocked` is 0 until then.
- A collector counts as nobody watching: a JetKVM that is not on screen is only asked whether it answers, and its one viewer stays free.
- `GET /healthz` needs no token. It says that qKVM is running, its version, and whether it still waits for a sign-in after a restart (`"locked"`).

## Related

- [Alerts](https://qkvm.com/docs/web/alerts)
- [History](https://qkvm.com/docs/web/history)
- [Keeping it running](https://qkvm.com/docs/web/keeping-it-running)
- [Advanced server settings](https://qkvm.com/docs/web/advanced-server-settings)

[Full reference](https://github.com/qkvm/qkvm/blob/main/GUIDE.md#metrics)
