Episode 18: Portainer CE, Arcane, Dockge and Komodo measured next to a running stack

This commit is contained in:
Maximilian Grimm 2026-10-17 16:30:10 +02:00
parent 55b2fe7646
commit 76a3132a17
42 changed files with 1639 additions and 0 deletions

50
managers/lib.sh Normal file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env bash
# ep18 Lab-Helfer auf der Box. Nur lesen/messen, keine Geheimnisse im Output.
now() { date +%s.%N; }
ts() { date -u +%H:%M:%S; }
el() { python3 -c "print(f'{float(\"$2\")-float(\"$1\"):.2f}')"; }
# waitui URL [max_s]: wartet, bis die URL mit 2xx/3xx antwortet, druckt jede Änderung des Status
waitui() { local url=$1 max=${2:-300} t0=$(now) last=""; while :; do
c=$(curl -sk -o /dev/null -m 2 -w '%{http_code}' "$url");
[ "$c" != "$last" ] && echo " $(ts) +$(el $t0 $(now)) s HTTP $c" && last=$c
case $c in 2*|3*) echo "UI reachable after $(el $t0 $(now)) s"; return 0;; esac
[ $(python3 -c "print(int(float('$(now)')-float('$t0')))") -ge $max ] && echo "TIMEOUT" && return 1; sleep 0.2; done; }
# stats5 NAME_REGEX SECONDS: docker stats im 5-s-Takt, dann Mittel/Max je Container und Summe
stats5() { local re=$1 dur=${2:-300} f=$(mktemp) t0=$(date +%s); echo "# docker stats --no-stream every 5 s for $dur s, containers matching /$re/, start $(ts) UTC"
while [ $(( $(date +%s) - t0 )) -lt $dur ]; do s=$(date +%s.%N)
docker stats --no-stream --format '{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}' | awk -F'\t' -v re="$re" '$1 ~ re' | sed "s/^/$(ts)\t/" | tee -a $f
sleep $(python3 -c "print(max(0,5-($(now)-$s)))"); done
python3 - $f <<'PY'
import sys,collections
u={'B':1/2**20,'KiB':1/1024,'MiB':1,'GiB':1024,'kB':1/1024/1000*1024,'MB':1}
def mib(s):
s=s.strip()
for k in ['GiB','MiB','KiB','kB','MB','B']:
if s.endswith(k): return float(s[:-len(k)])*u[k]
d=collections.defaultdict(lambda:{'cpu':[],'mem':[]}); per=collections.defaultdict(lambda:[0,0])
for l in open(sys.argv[1]):
t,n,c,m=l.rstrip('\n').split('\t'); c=float(c.rstrip('%')); m=mib(m.split('/')[0])
d[n]['cpu'].append(c); d[n]['mem'].append(m); per[t][0]+=c; per[t][1]+=m
print(f"\n{'container':40} {'samples':>7} {'CPU% mean':>9} {'CPU% max':>9} {'RAM MiB mean':>12} {'RAM MiB max':>11}")
for n,v in sorted(d.items()):
print(f"{n:40} {len(v['cpu']):7} {sum(v['cpu'])/len(v['cpu']):9.2f} {max(v['cpu']):9.2f} {sum(v['mem'])/len(v['mem']):12.1f} {max(v['mem']):11.1f}")
c=[x[0] for x in per.values()]; m=[x[1] for x in per.values()]
print(f"{'TOTAL (sum per sample)':40} {len(c):7} {sum(c)/len(c):9.2f} {max(c):9.2f} {sum(m)/len(m):12.1f} {max(m):11.1f}")
PY
rm -f $f; }
# watchrun PROJECT N [max_s]: wartet, bis alle Container des Projekts mit RUN=N laufen; Zeit ab T0 (Env T0)
watchrun() { local p=$1 n=$2 max=${3:-180} t0=${T0:-$(now)}; while :; do
ids=$(docker ps -q --filter label=com.docker.compose.project=$p); ok=0; tot=0
for i in $ids; do tot=$((tot+1)); docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}{{.State.Running}}' $i 2>/dev/null | grep -q "^RUN=$n$" && ok=$((ok+1)); done
if [ $tot -ge 2 ] && [ $ok -eq $tot ]; then echo " RUN=$n: $ok/$tot containers running after $(el $t0 $(now)) s"; return 0; fi
[ $(python3 -c "print(int(float('$(now)')-float('$t0')))") -ge $max ] && echo " TIMEOUT RUN=$n ($ok/$tot)" && return 1; sleep 0.1; done; }
# imgsize IMAGE...: Größe laut docker image ls (containerd-Speicher zeigt Plattenbedarf und Inhalt)
imgsize() { docker image ls --format 'table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}' | head -1; for i in "$@"; do docker image ls --format '{{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}' | grep -F "$i" ; done; for i in "$@"; do echo "$i inspect .Size = $(docker image inspect -f '{{.Size}}' $i | numfmt --to=iec-i --suffix=B)"; done; }
# regdigest REPO TAG: Index-Digest auf Docker Hub (ohne buildx)
regdigest() { local t=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$1:pull" | jq -r .token)
curl -sI -H "Authorization: Bearer $t" -H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json' "https://registry-1.docker.io/v2/$1/manifests/$2" | awk 'tolower($1)=="docker-content-digest:"{print $2}' | tr -d '\r'; }