Volumes page: on-demand volume sizes (0.18.0)

Docker's volume list has no size, so add a "Compute sizes" button that runs
`docker system df` (via client.df()) and shows per-volume size in a new Size
column. The df walk is expensive (seconds), so results are cached ~60s and
loaded on demand instead of on every poll.

- volume_service.volume_sizes(force) with a 60s TTL cache; GET /api/volumes/sizes
  + agent /agent/volumes/sizes + proxy /api/agents/{id}/volumes/sizes.
- Frontend: volumesApi.sizes(force, agentId); Volumes page gained a Size column
  and a Compute sizes button (per host) that triggers the lookup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
menzelj
2026-06-08 13:07:07 +00:00
co-authored by Claude Opus 4.8
parent 8f6e354b3f
commit 56450efd82
9 changed files with 96 additions and 5 deletions
+29
View File
@@ -1,6 +1,8 @@
"""Docker volume management + Compose volume YAML generation."""
from __future__ import annotations
import threading
import time
from typing import Literal, Optional
import yaml
@@ -9,6 +11,33 @@ from docker_client import get_client, safe_call
COMPOSE_PROJECT_LABEL = "com.docker.compose.project"
# `docker system df -v` walks every volume's contents, so it can take many
# seconds. Cache the result so the (polled) UI and repeated requests reuse it.
_SIZE_TTL = 60.0
_size_cache: dict = {"at": 0.0, "data": {}}
_size_lock = threading.Lock()
def volume_sizes(force: bool = False) -> dict:
"""Return {volume_name: size_bytes|None}. Cached (~60s) since it's expensive."""
now = time.time()
with _size_lock:
if not force and _size_cache["data"] and now - _size_cache["at"] < _SIZE_TTL:
return _size_cache["data"]
client = get_client()
df = safe_call(client.df)
sizes: dict[str, Optional[int]] = {}
for v in df.get("Volumes") or []:
ud = v.get("UsageData") or {}
size = ud.get("Size")
sizes[v.get("Name")] = size if isinstance(size, int) and size >= 0 else None
with _size_lock:
_size_cache["at"] = time.time()
_size_cache["data"] = sizes
return sizes
# --------------------------------------------------------------------------- #
# Listing / pruning