From 15d979e9c683358f6b1dff628749732b6df199dc Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Sat, 13 Feb 2021 17:05:42 +0100 Subject: [PATCH] Add export script --- .gitignore | 1 + README.md | 34 ++++++++++++++++++++++++++++++++++ save_docker_stats.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 save_docker_stats.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..497d582 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +stats.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..07a8836 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ + +Ultra-light docker monitor +========================= + +This light tool permits: + - to export docker container memory usage in a JSON file `stats.json` + - display curves of the memory usages using the JSON file + +The export and the display are two different parts. This allow to run the display in another machine. + + + +Setup the stats export +---------------------- + +To add it to the cron tab: + + crontab -e + +The add new line (to run the check once per hour) + + */10 * * * * /path.io/docker-stats-histo/save_docker_stats.sh >>/dev/null 2>&1 + + +**Note:** + - Normaly cron send task outputs (echo) via mail. As the MTA (Mail Transfert Agent), may not be set up, +the crontab line redirect the outputs into `/dev/null`. Can also be a path to a log file. + - No sudo is needed, crontab is called with current user. + + +Display stats +------------- + +To be done... diff --git a/save_docker_stats.sh b/save_docker_stats.sh new file mode 100755 index 0000000..ba288c5 --- /dev/null +++ b/save_docker_stats.sh @@ -0,0 +1,28 @@ +#!/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