# History

qKVM keeps what it saw of each machine in `history.sqlite`, in the data folder. The activity log says who did what; the history says what happened to the machines.

## What it keeps

| Kept | When |
|---|---|
| The state of the tile | at each change |
| When the machine was last heard from | at each look |
| Readings: a KVM's own temperature, a server's temperatures and fans | about once a minute, sooner when a reading moves by a few degrees |
| Power events | every power button pressed from the wall, and every change of power state seen |

A row holds a device's id, a time, and a state, a reading or the name of a button. Never a name, an address, a password or typed text.

## On the tile

Enlarged, a tile says when the machine was last seen, how much of this week it was online, and shows a graph of the last day for each kind of reading.

"Online 99.2 % this week" counts only the time the wall was watching. A wall that was stopped or locked saw nothing then, and that time counts neither as online nor as down. Where more than a tenth of the week was not watched, the line says so.

While qKVM is unlocked it looks at every machine once a minute by itself, whether or not anybody has the wall open.

## How much is kept

| Option | What it does | Default |
|---|---|---|
| `history_days` | days kept, 1 to 3650 | 90 |
| `history_mb` | megabytes kept, 10 to 100000, the file and its `-wal` file together | 200 |

The oldest rows go first. Change the limits with [Advanced server settings](https://qkvm.com/docs/web/advanced-server-settings). A server with forty readings writes about 2 MB a day, a KVM a few hundred kB. `qkvm status` says how large the history is.

## Good to know

- It is in no export, and an import leaves it alone. A backup holds it where *With the history* is ticked, and a copy of the data folder carries it.
- A machine taken off the wall takes its history with it.
- A file that cannot be read is moved aside and a fresh one is started: the wall comes up either way.
- A program outside qKVM that keeps the file open (a database browser, Litestream) keeps its `-wal` file growing until it lets go.

## For a script

With a viewer's token or better, for a machine the account may see:

```
GET /api/v1/devices/{id}/history?what=summary&since=&until=&limit=&every=
```

| `what` | Answers |
|---|---|
| `summary` (default) | first and last seen, last state and power, seconds `watched` and `online`, `share`, the names of its `sensors` |
| `states` | `rows` of `{t, state, code}` |
| `events` | `rows` of `{t, kind, what, ok, note}`, where `kind` is `pressed` or `power` |
| `samples` | `rows` of `{t, sensor, unit, value}`; with `every=900`, a `series` per sensor of averages, minimums and maximums |

Times are in seconds since 1970. The window is the last week, for samples the last day, unless `since` and `until` say otherwise. `limit` is 1000 unless given, 5000 at the most, and `more` says the page was cut.

## Related

- [Metrics](https://qkvm.com/docs/web/metrics)
- [Activity log](https://qkvm.com/docs/web/activity-log)
- [The API](https://qkvm.com/docs/web/the-api)
- [Backups](https://qkvm.com/docs/web/backups)

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