feat(docker): collect + persist /system/df image/disk usage (agent 1.6.0)
Backend for the image/disk panel (milestone 77 #942). Agent gains collect_disk_usage() — one /system/df call (gated on containers existing, so Docker-less hosts pay nothing), surfacing reclaimable bytes (image size held by unreferenced images), layers/containers/volumes/build-cache sizes, and the top 50 images by size. Emitted as sample["docker_disk"]; host_agent ingest tracks the newest sample's copy and hands it to the docker capability as a 5th arg. New current-state tables docker_disk_usage (one row/host) + docker_images (per-host image rows), docker_007 migration; ingest upserts the summary and replaces the image set per host (stale images pruned). Unit tests for the df parsing/reclaimable math + build_sample gating; integration test for persistence + image-set replacement. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016Jg27rgypiW2efULXJDtMC
This commit is contained in:
@@ -189,6 +189,56 @@ class DockerSwarmService(Base):
|
||||
)
|
||||
|
||||
|
||||
class DockerDiskUsage(Base):
|
||||
"""Per-host Docker disk usage summary from `/system/df` (current state).
|
||||
|
||||
One row per host (the agent re-reports the full summary each interval).
|
||||
Reclaimable = bytes held by images no container references. Sizes are bytes
|
||||
(BigInteger — image caches exceed 2^31 easily).
|
||||
"""
|
||||
__tablename__ = "docker_disk_usage"
|
||||
|
||||
host_id: Mapped[str] = mapped_column(
|
||||
String(36), ForeignKey("hosts.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
layers_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
images_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
images_reclaimable: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
containers_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
volumes_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
build_cache_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
images_total: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
images_active: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
containers_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
volumes_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False,
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
|
||||
class DockerImage(Base):
|
||||
"""Per-host image storage record (the heavy hitters from `/system/df`).
|
||||
|
||||
Keyed (host_id, image_id); `containers` is the reference count (0 ⇒ the
|
||||
image's size is reclaimable). Replaced wholesale per host on each report.
|
||||
"""
|
||||
__tablename__ = "docker_images"
|
||||
|
||||
host_id: Mapped[str] = mapped_column(
|
||||
String(36), ForeignKey("hosts.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
image_id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
repo_tag: Mapped[str] = mapped_column(String(512), nullable=False, default="<none>")
|
||||
size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
shared_size: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
||||
containers: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False,
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
|
||||
class DockerSwarmNode(Base):
|
||||
"""A Swarm node as seen by a manager host: role / availability / status."""
|
||||
__tablename__ = "docker_swarm_nodes"
|
||||
|
||||
Reference in New Issue
Block a user