From 4637e60ec4c1cdfeab2d1f94aa2eeee05ba65718 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 8 Mar 2026 14:06:23 +1300 Subject: [PATCH] Add Docker container discovery with stats, image display, and CPU usage bars --- app/gather_info.sh | 27 +++++++++++++++++++++++++++ app/static/style.css | 9 +++++++++ app/templates/index.html | 19 ++++++++++++++++++- setup-remote.sh | 4 ++-- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/app/gather_info.sh b/app/gather_info.sh index d33e83a..5cde826 100755 --- a/app/gather_info.sh +++ b/app/gather_info.sh @@ -279,4 +279,31 @@ if command -v virsh &>/dev/null; then done fi +# Docker containers +if command -v docker &>/dev/null; then + _sudo docker ps -a --format '{{.Names}}\t{{.State}}\t{{.Image}}\t{{.Status}}' 2>/dev/null | while IFS=$'\t' read -r name state image status_text; do + [ -z "$name" ] && continue + echo "[container:docker-${name}]" + echo "type=docker" + echo "platform=docker" + echo "name=$name" + echo "status=$state" + echo "image=$image" + echo "status_text=$status_text" + if [ "$state" = "running" ]; then + # Get IP from docker inspect + docker_ip=$(_sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$name" 2>/dev/null) + [ -n "$docker_ip" ] && echo "ip=$docker_ip" + # Get memory/cpu stats (one-shot, no stream) + stats=$(_sudo docker stats --no-stream --format '{{.MemUsage}}\t{{.MemPerc}}\t{{.CPUPerc}}' "$name" 2>/dev/null) + if [ -n "$stats" ]; then + mem_pct=$(echo "$stats" | cut -f2 | tr -d '%') + cpu_pct=$(echo "$stats" | cut -f3 | tr -d '%') + echo "mem_percent=${mem_pct}" + echo "cpu_percent=${cpu_pct}" + fi + fi + done +fi + echo "[end]" diff --git a/app/static/style.css b/app/static/style.css index b91b43e..c81021b 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -386,6 +386,15 @@ main { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; } +.ct-image { + font-size: 0.7rem; + color: #475569; + margin-bottom: 4px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + .ct-status-label { color: #64748b; font-style: italic; diff --git a/app/templates/index.html b/app/templates/index.html index 4414942..46e13ee 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -264,6 +264,9 @@ {{ ct.get('name', ct.get('id', '?')) }} {{ ct.get('type', '')|upper }} + {% if ct.get('image') %} +
{{ ct.get('image') }}
+ {% endif %} {% if ct_running %}
{% if ct.get('ip') %} @@ -272,9 +275,22 @@ {% if ct.get('uptime_seconds') %} {{ ct.get('uptime_seconds', '')|format_uptime }} {% endif %} + {% if ct.get('status_text') %} + {{ ct.get('status_text') }} + {% endif %}
- {% if ct.get('mem_percent') %} + {% if ct.get('mem_percent') or ct.get('cpu_percent') %}
+ {% if ct.get('cpu_percent') %} +
+ CPU +
+
+
+ {{ ct.get('cpu_percent', '0') }}% +
+ {% endif %} + {% if ct.get('mem_percent') %}
RAM
@@ -282,6 +298,7 @@
{{ ct.get('mem_percent', '0') }}%
+ {% endif %} {% if ct.get('disk_percent') %}
DISK diff --git a/setup-remote.sh b/setup-remote.sh index 640a5b0..44a6904 100755 --- a/setup-remote.sh +++ b/setup-remote.sh @@ -196,7 +196,7 @@ install_packages # Some sensor/DMI files need group access if [ "$OS" != "openwrt" ]; then # Add infmap to common hardware-access groups if they exist - for group in i2c sensors; do + for group in i2c sensors docker; do getent group "$group" &>/dev/null && usermod -aG "$group" "$USERNAME" 2>/dev/null || true done fi @@ -207,7 +207,7 @@ SUDOERS_FILE="/etc/sudoers.d/infmap" SUDO_CMDS="" # Detect which hypervisor tools are present (check common sbin paths too) -for cmd in pct qm lxc virsh; do +for cmd in pct qm lxc virsh docker; do cmd_path=$(command -v "$cmd" 2>/dev/null) # Also check sbin paths not always in PATH if [ -z "$cmd_path" ]; then