forked from mtusi2026/mtusi2026lab6
Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files. Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
16 lines
778 B
Bash
Executable File
16 lines
778 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
out=${1:?usage: docker-stats.sh <csv>}
|
|
vm=$(dirname "$out")/vm_stat.csv
|
|
cd "$(dirname "$0")/.."
|
|
project=$(docker compose config | sed -n 's/^name: //p')
|
|
echo 'ts,name,cpu_pct,mem_usage,mem_pct,net_io,block_io,pids' > "$out"
|
|
echo 'ts,busy,total,cpus' > "$vm"
|
|
while :; do
|
|
ts=$(date +%s)
|
|
docker compose exec -T valkey cat /proc/stat 2>/dev/null | awk -v ts="$ts" '/^cpu /{b=$2+$3+$4+$7+$8+$9; t=b+$5+$6} /^cpu[0-9]/{n++} END{if (t) print ts "," b "," t "," n}' >> "$vm" || true
|
|
ids=$(docker ps -q --filter "label=com.docker.compose.project=$project")
|
|
[ -z "$ids" ] || docker stats --no-stream --format "$ts,{{.Name}},{{.CPUPerc}},{{.MemUsage}},{{.MemPerc}},{{.NetIO}},{{.BlockIO}},{{.PIDs}}" $ids >> "$out" || true
|
|
sleep "${INTERVAL:-1}"
|
|
done
|