Add export script
This commit is contained in:
commit
15d979e9c6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
stats.json
|
34
README.md
Normal file
34
README.md
Normal file
@ -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...
|
28
save_docker_stats.sh
Executable file
28
save_docker_stats.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user