docker-stats-histo/save_docker_stats.sh

29 lines
539 B
Bash
Raw Normal View History

2021-02-13 16:05:42 +00:00
#!/usr/bin/env bash
set -eu
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
OUTPUT="stats.json"
# Move in repo folder
pushd ${SCRIPT_PATH} > /dev/null
# If file does not exist, create it with JSON bracket
if [ ! -f $OUTPUT ]; then
echo "[" >> ${OUTPUT}
fi
# Append stat data
now=$(date -Iseconds)
echo "{" >> ${OUTPUT}
echo " \"data\": \"${now}\"" >> ${OUTPUT}
/snap/bin/docker stats --no-stream --format " ,\"{{.Name}}\": \"{{.MemUsage}}\"" >> ${OUTPUT}
echo "}," >> ${OUTPUT}
# Back to original path
popd