container details: limits, sandbox flags and a live stats sample

Container details now carry the image id and the HostConfig resource limits
(CPU cores and shares, memory and swap bytes, pids, device requests) plus sandbox flags
(privileged, read-only rootfs, network mode, restart policy), with null meaning unlimited. A new
GET /api/v1/docker/containers/{name}/stats returns one live sample: CPU percent
of one core, memory working set, processes, block IO and network bytes. Peers
proxy the new route.

Env, labels, command lines and mounts are deliberately excluded from the payload.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
HermenixandClaude Sonnet 5.5 committed 2026-11-05 03:02:33 +00:00
1 parent 72fccc34f8
commit 0ff3520563
16 files changed
+947 -19

No files matched your search

+2 -1
View File
@@ -81,7 +81,7 @@ Precedence: defaults < config file (`--config`, default `/etc/skyg-linux-tracker
- **systemd** (`sources/systemd.rs`): one shared system-bus `zbus::Connection`. `list_units(state)` uses `ListUnits`. `list_timers()` lists `*.timer` units (`ListUnitsByPatterns`) and reads the `Timer` interface on each (`NextElapseUSecRealtime`, `LastTriggerUSec`, `Unit`); `0` or `u64::MAX` means not scheduled. `unit_status(name)` uses `GetUnit` only, never `LoadUnit`, so an unloaded unit is NotFound. `Unit` properties are read for every unit, `Service` properties (`ExecMainStatus`, `NRestarts`) only for `.service` units, so those DTO fields are `Option`. Unit names are validated. No caching.
- **journal** (`sources/journal.rs`): all sd-journal access runs inside `spawn_blocking` (a `Journal` is neither `Send` nor `Sync` and is opened and kept in the blocking closure). `query(filter)` seeks backward N entries (unit, priority <= N, `lines` capped by `limits.max_lines`, returned oldest first). `follow(filter)` is a blocking `wait()` loop with a short timeout that feeds an mpsc channel and exits when the receiver is dropped or the shutdown token fires. Binary `MESSAGE` fields are mapped lossily. `sources.journal_namespace` opens a journal namespace.
- **docker** (`sources/docker.rs`): lazily constructed `bollard::Docker` on `sources.docker_socket`. A missing or denied socket never fails startup; each call maps it to `AppError::Unavailable` (HTTP 503 on docker routes only). `ps()` lists containers and inspects them concurrently (bounded) for health, uptime, restart count and image. `logs(name, follow, tail, since)` is a stream that stops on drop or shutdown; `tail` is capped by `limits.max_tail`.
- **docker** (`sources/docker.rs`): lazily constructed `bollard::Docker` on `sources.docker_socket`. A missing or denied socket never fails startup; each call maps it to `AppError::Unavailable` (HTTP 503 on docker routes only). `ps()` lists containers and inspects them concurrently (bounded) for health, uptime, restart count and image. `container_status()` adds the sandbox facts a frozen box otherwise hides: `image_id`, and `resources` (CPU cores, memory and swap limits, pids limit, privileged, read-only rootfs, restart policy, network mode, device requests such as a CDI GPU). Those come from `HostConfig` only — `Env`, `Labels`, `Cmd`, `Args` and mounts are never copied, so no credential can reach the API. `stats(name)` takes one `/stats` sample (`stream=false`, `one-shot=true`) and derives CPU percent from the container/system deltas against `online_cpus`, a working set (usage minus page cache) and IO counters. `logs(name, follow, tail, since)` is a stream that stops on drop or shutdown; `tail` is capped by `limits.max_tail`.
## REST API
@@ -96,6 +96,7 @@ All under `/api/v1`, GET only, behind the auth middleware when enabled. Routes u
| `GET /api/v1/journal/follow?unit=&priority=` (SSE, event `journal`) | journal `follow()` |
| `GET /api/v1/docker/ps` | `ps()` |
| `GET /api/v1/docker/containers/{name}` | `container_status()` |
| `GET /api/v1/docker/containers/{name}/stats` | `stats()` — one live sample (CPU, memory, pids, block IO, network) |
| `GET /api/v1/docker/containers/{name}/logs?tail=&since=&follow=0\|1` (JSON, or SSE events `stdout`/`stderr`) | `logs()` |
| `GET /api/v1/ping` | authenticated liveness, used by a consolidator's API check |
| `GET /api/v1/openapi.json` | generated OpenAPI 3.1 document; peer paths and tools only when peers are enabled |