27 lines
924 B
Bash
Executable File
27 lines
924 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
stop_file="${1:?stop file is required}"
|
|
interval_seconds="${2:-1}"
|
|
phase_file="${3:-}"
|
|
|
|
if ! [[ "$interval_seconds" =~ ^[1-9][0-9]*$ ]]; then
|
|
echo "Sampling interval must be a positive integer." >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s\n' 'captured_at,phase,load_1m,mem_available_kib,container,cpu_percent,memory_usage,network_io,block_io,pids'
|
|
while [[ ! -e "$stop_file" ]]; do
|
|
captured_at="$(date --iso-8601=seconds)"
|
|
phase=""
|
|
if [[ -n "$phase_file" && -r "$phase_file" ]]; then
|
|
phase="$(tr -cd 'A-Za-z0-9_.-' < "$phase_file")"
|
|
phase="${phase:0:120}"
|
|
fi
|
|
load_1m="$(awk '{print $1}' /proc/loadavg)"
|
|
mem_available_kib="$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo)"
|
|
docker stats --no-stream \
|
|
--format "${captured_at},${phase},${load_1m},${mem_available_kib},{{.Name}},{{.CPUPerc}},{{.MemUsage}},{{.NetIO}},{{.BlockIO}},{{.PIDs}}"
|
|
sleep "$interval_seconds"
|
|
done
|