A light tool to supervise docker memory usage (save memory usage in sqlite then display it in html report).
Go to file
2022-02-27 17:18:09 +01:00
.gitignore Mr Propre 2021-11-21 15:53:34 +01:00
generate_html.py Default behavior : display stats for the last 30 days only 2022-02-27 17:18:09 +01:00
generate_html.sh Default behavior : display stats for the last 30 days only 2022-02-27 17:18:09 +01:00
README.md Doc 2021-12-03 00:06:42 +01:00
requirements.txt Update doc 2021-11-21 19:03:58 +01:00
save_docker_stats.py Mr Propre 2021-11-21 15:53:34 +01:00
save_docker_stats.sh Update sh workflow 2021-12-02 21:01:26 +01:00

Ultra-light docker monitor

This light tool permits:

  • 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 allows to run the display in another machine.

Install python virtual env

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:

./venv/bin/activate
python --version
...
deactivate

Export stats

./save_docker_stats.sh
or
python save_docker_stats.py

Display stats

This step permits to generate an html interactive render from the sqlite stats file. It is simple, just run:

./generate_html.sh

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 eunuque.caracals.org:/home/caracals/outils/docker-stats-histo/stats.sqlite .

Automations using cron

Open the cron tab in edition mode:

crontab -e

Then add those lines (to run the check each 10 minutes and a html generation each hour)

*/10 * * * * /path/to/docker-stats-histo/save_docker_stats.sh > /dev/null  2>&1
00 */1 * * * /path/to/docker-stats-histo/generate_html.sh > /dev/null  2>&1

Note:

  • 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.

Advanced parameters

Both python scripts can have a finer configuration (sqlite and html paths). To see all accepted parameters use -h flag, like

python save_docker_stats.py -h
python generate_html.py -h