report configured containers Docker never lists as stopped

A name in SERVICES_ALIASES with no matching container (typo or deleted)
produced no `docker ps -a` line, so it silently vanished from the
dashboard instead of showing as a problem. Track which configured names
were seen and append the leftovers as stopped, logging edge-triggered so
a persistent typo doesn't reprint every 2s poll.

Also corrects the kcmonitor container name and refreshes the README
service list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 15:46:01 +09:00
parent a20a8f3552
commit 8a9e8ba7ff
2 changed files with 24 additions and 2 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ Pushes a JSON object every 2 seconds with real system metrics from `psutil`:
- `cpu_pct`, `mem_pct`, `mem_used_mb`, `disk_pct`
- `cpu_temp` (reads `/sys/class/thermal/` as fallback)
- `uptime_hrs`, `net_rx_kbps`, `net_tx_kbps` (values are in kB/s despite the field names)
- `services` — live Docker container statuses via `docker ps -a`, with a ternary status model (`running`, `warning`, `stopped`). Monitored containers: gitea, samba, pihole, qbittorrent, frpc (ny), pinepods, frpc (ssh), jellyfin.
- `services` — live Docker container statuses via `docker ps -a`, with a ternary status model (`running`, `warning`, `stopped`). Monitored containers: gitea, samba, pihole, qbittorrent, frpc (ny), pinepods, frpc (ssh), jellyfin, kc-start2, kc-monitor. A configured container Docker doesn't report at all (deleted, or a typo in `SERVICES_ALIASES`) is reported as `stopped` and logged once to stdout.
- `local_time` fields for RTC sync (`y`, `mo`, `d`, `h`, `m`, `s`)
### contents_server.py -- port 8766
+23 -1
View File
@@ -71,8 +71,13 @@ SERVICES_ALIASES = {
"frpc-ssh": "frpc (ssh)",
"jellyfin": "jellyfin",
"kancolle-start2-server": "kc-start2",
"kancolle": "kc-monitor",
"kancolle-kcmonitor": "kc-monitor",
}
# Configured names Docker didn't report, so a typo doesn't reprint every 2s
_missing_containers: set[str] = set()
def _get_docker_services() -> list[dict]:
"""Query Docker for real container statuses with ternary status model."""
try:
@@ -86,7 +91,10 @@ def _get_docker_services() -> list[dict]:
if result.returncode != 0:
return []
global _missing_containers
services = []
seen = set()
for line in result.stdout.strip().splitlines():
parts = line.split("\t", 1)
if len(parts) != 2:
@@ -102,6 +110,20 @@ def _get_docker_services() -> list[dict]:
else:
status = "stopped"
services.append({"name": SERVICES_ALIASES[name], "status": status})
seen.add(name)
# A configured name Docker never reported is either a typo or a deleted
# container — show it as stopped instead of dropping it off the dashboard
missing = set(SERVICES_ALIASES) - seen
for name in sorted(missing):
services.append({"name": SERVICES_ALIASES[name], "status": "stopped"})
if missing != _missing_containers:
for name in sorted(missing - _missing_containers):
print(f"No container named {name!r} — reporting as stopped")
for name in sorted(_missing_containers - missing):
print(f"Container {name!r} is back")
_missing_containers = missing
# Sort: warnings first, then stopped, then running (problems float to top)
order = {"warning": 0, "stopped": 1, "running": 2}