be4654fc72
- Add HTTP monitor plugin: endpoint checking with status history, latency tracking, time-range views - Add SNMP plugin: OID polling, device management, metric recording - Add Docker plugin: container status, resource usage, widget - Traefik: access log widget, request chart widget, expanded routes - UniFi: clients widget, devices widget, expanded poll routes - UPS: history widget, additional routes - Update plugin index with new entries Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
2.4 KiB
Python
50 lines
2.4 KiB
Python
# plugins/docker/models.py
|
|
from __future__ import annotations
|
|
import uuid
|
|
from datetime import datetime, timezone
|
|
from sqlalchemy import DateTime, Float, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from fabledscryer.models.base import Base
|
|
|
|
|
|
class DockerContainer(Base):
|
|
"""Latest known state per container — upserted by name on each scrape."""
|
|
__tablename__ = "docker_containers"
|
|
|
|
# Container name is the stable natural key; container_id changes on recreation
|
|
name: Mapped[str] = mapped_column(String(255), primary_key=True)
|
|
container_id: Mapped[str] = mapped_column(String(64), nullable=False, default="")
|
|
image: Mapped[str] = mapped_column(String(512), nullable=False, default="")
|
|
status: Mapped[str] = mapped_column(String(32), nullable=False, default="unknown")
|
|
# running | stopped | paused | exited | dead
|
|
cpu_pct: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
mem_usage_bytes: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
mem_limit_bytes: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
mem_pct: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
restart_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
ports_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
|
|
# JSON: [{"host_port": 8080, "container_port": 80, "protocol": "tcp"}]
|
|
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
scraped_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False,
|
|
default=lambda: datetime.now(timezone.utc),
|
|
)
|
|
|
|
|
|
class DockerMetric(Base):
|
|
"""Time-series CPU/memory per container — one row per scrape per running container."""
|
|
__tablename__ = "docker_metrics"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
|
)
|
|
container_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
|
scraped_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False,
|
|
default=lambda: datetime.now(timezone.utc),
|
|
index=True,
|
|
)
|
|
cpu_pct: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
|
mem_pct: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
|
mem_usage_bytes: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|