#!/bin/bash # guest_sampler.sh TAG — runs INSIDE the Felhom guest. Every 5 s, one line per running container: # ts name mem_current anon inactive_file shmem cpu_usage_usec # read straight from the container's cgroup v2 files (no docker stats: cheaper, and exact). # Stops when /root/sizing/stop-TAG exists. Read-only: it writes only its own TSV. TAG=${1:?tag}; D=/root/sizing; mkdir -p "$D"; OUT="$D/guest-$TAG.tsv"; rm -f "$D/stop-$TAG" echo -e "ts\tname\tmem_current\tanon\tinactive_file\tshmem\tcpu_usage_usec" > "$OUT" declare -A NAME; last=0 while [ ! -e "$D/stop-$TAG" ]; do now=$(date +%s) if (( now - last >= 30 )); then # refresh the id->name map every 30 s NAME=(); while read -r id n; do NAME[$id]=$n; done < <(docker ps --no-trunc --format '{{.ID}} {{.Names}}') last=$now fi for id in "${!NAME[@]}"; do cg=/sys/fs/cgroup/system.slice/docker-$id.scope [ -r "$cg/memory.current" ] || continue cur=$(<"$cg/memory.current") read -r anon inf shm < <(awk '$1=="anon"{a=$2} $1=="inactive_file"{i=$2} $1=="shmem"{s=$2} END{print a,i,s}' "$cg/memory.stat") cpu=$(awk '$1=="usage_usec"{print $2}' "$cg/cpu.stat") echo -e "$now\t${NAME[$id]}\t$cur\t$anon\t$inf\t$shm\t$cpu" done >> "$OUT" sleep 5 done