Skip to content
Kaiov0.8.0

Data retention

A cleanup loop runs every hour and applies three policies you can tune.

Data Kept for Configurable
container_metrics 24 hours Yes, KAIO_METRICS_RETENTION_HOURS
events 30 days Yes, KAIO_EVENTS_RETENTION_DAYS
audit_log 90 days Yes, KAIO_AUDIT_RETENTION_DAYS
containers Current state only Rows follow the host, deleted with the container
stacks, stack_versions, stack_env Forever Deleted with the stack, or per version with stack version-rm
image_scans One row per image, overwritten by the next scan Removed when the image goes

The poller samples every running or paused container every 15 seconds, so a single container writes about 240 rows per hour, or 5,760 per day. With the default 24 hour window, the table settles at roughly that many rows per container and stops growing:

Containers Rows at steady state
10 ~58,000
50 ~288,000
200 ~1,150,000

The table grows in proportion to the window: 48 hours doubles these figures, a week multiplies them by seven.

Stopped containers cost nothing: the poller only fetches stats for containers that are running or paused.

Rows outlive their container. They carry the stack and the container name, so a stack whose containers an update recreates keeps its charts, and only the retention window removes them. The same goes for a stack deleted and deployed again under the same name within that window: it picks up the history of the one before.

Change the window in hours:

Terminal window
KAIO_METRICS_RETENTION_HOURS=48

The charts read the same table, so no interface can show a metric older than the window. The web dashboard offers 1, 6, 12 or 24 hours and greys out what the server does not keep; a shorter retention caps every chart at it. For history measured in weeks, scrape Kaio with Prometheus rather than stretching this table: Prometheus keeps what it has seen for as long as you tell it to, without growing the database Kaio reads on every poll.

Events hold the long history, a month by default:

Terminal window
KAIO_EVENTS_RETENTION_DAYS=90

Set it to something long if you use events as a deployment log. They carry what happened and when, never who did it, so they are a timeline rather than an audit trail.

These are the rows that accumulate without limit, and the only ones that should. Every deploy writes a version holding the full compose file and a snapshot of the environment. A stack redeployed daily for a year carries 365 versions.

Prune them when the history stops being useful:

Terminal window
kaio-cli stack versions my-db
kaio-cli stack version-rm my-db 12

Deleting a stack removes its versions with it.

SQLite does not return freed pages to the filesystem on its own. After a large cleanup, compact the file with the server stopped:

Terminal window
docker compose stop kaio
sqlite3 data/kaio.db "VACUUM;"
docker compose start kaio

Take a backup first: VACUUM rewrites the whole database.

The audit log writes one row per sensitive action or refusal, never one per read, so it grows with what people and agents do rather than with the size of the host: a few hundred rows a day on a busy server. It is kept 90 days by default, longer than events, because it is what you reach for when asking who did something weeks ago:

Terminal window
KAIO_AUDIT_RETENTION_DAYS=365

A value of 0 or one that does not parse keeps the default rather than deleting everything.

Kaio, built by Régis Gaidot