From de08178784ddfdbeb26638744763b0d4142a8352 Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Sun, 21 Nov 2021 19:02:31 +0100 Subject: [PATCH] Update doc --- README.md | 92 ++++++++++++++++++++++++-------------------- requirements.txt | 2 +- save_docker_stats.sh | 14 +++++++ 3 files changed, 65 insertions(+), 43 deletions(-) create mode 100644 save_docker_stats.sh diff --git a/README.md b/README.md index 10c540d..913729a 100644 --- a/README.md +++ b/README.md @@ -3,40 +3,52 @@ WIP === -- [ ] Ajouter parsing des noms -- [ ] tester python avec le cron root et venv -- [ ] Log dans fichier -- [ ] exporter anciennes stats dans JSON -- [ ] mettre en place le nouveau cron -- [ ] ajouter un 2e cron pour la generation du html - [ ] Date de génération dans la page html 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 + - to export docker container memory usage in a database `data.sqlite` + - display curves of the memory usages in an interactive html report -The export and the display are two different parts. This allow to run the display in another machine. +The export and the display are two different parts. This allows to run the display in another machine. +Install python virtual env +-------------------------- +```bash +sudo apt install python3.8 python3.8-venv +python3.8 -m venv venv +. venv/bin/activate +pip install --upgrade pip +pip install -r requirements.txt +``` +The python env is now callable in `venv/bin/python`. +Or by activating the virtual env: +```bash +./venv/bin/activate +python --version +... +deactivate +``` -Setup the stats export ----------------------- - +Configure the stats export +-------------------------- Open the cron tab in edition mode: +```bash +crontab -e +``` - crontab -e - -Then add a new line (to run the check each ten minutes) - - */10 * * * * /path.io/docker-stats-histo/save_docker_stats.sh >>/dev/null 2>&1 +Then add a new line (to run the check each 10 minutes) +```bash +*/10 * * * * /path/to/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), + - Normally cron send task outputs (echo) via mail. As the MTA (Mail Transfer Agent), may not be set up, the crontab line redirect the outputs into `/dev/null`. It can also be a path to a log file. - No sudo is needed, crontab is called with current user. @@ -44,28 +56,24 @@ It can also be a path to a log file. Display stats ------------- +This step permits to generate an html interactive render from the sqlite stats file. +It is simple, just run: +```bash +venv/bin/python generate_html.py +``` -This step permits to generate a render from a stats file (generated by the script -called by the crontab, see stats export section). - -### Install - -Need python3 with `venv` module - - sudo apt install python3 python3-venv - -### Run -Go in [display](display) folder - - cd display - -Then to generate a png, just run (install is automatically done if needed) - - ./render_stats.sh stats.json - -It is also possible to see a web version fo the render : - - ./render_stats.sh stats.json -w - +The report is now accessible in `stats.html. +` **Note:** if the stats file is in a remote server, one can use `scp` to get it: - scp alban@eunuque.caracals.org:/path/to/docker-stats-histo/stats.json . +```bash +scp eunuque.caracals.org:/home/caracals/outils/docker-stats-histo/stats.sqlite . +``` + +Advanced parameters +------------------- +Both python scripts can have a finer configuration. To see all accepted parameters use `-h` flag, like +```bash +python save_dcker_stats.py -h +python generate_html.py -h +``` + diff --git a/requirements.txt b/requirements.txt index 83297b7..c34033d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# For HTML rendering +# For HTML generation pandas plotly diff --git a/save_docker_stats.sh b/save_docker_stats.sh new file mode 100644 index 0000000..dd1f09f --- /dev/null +++ b/save_docker_stats.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -eu + +# Move in repo folder +SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +pushd ${SCRIPT_PATH} > /dev/null + + +venv/bin/python save_docker_stats.py + + +# Back to original path +popd > /dev/null