2021-02-13 16:05:42 +00:00
|
|
|
Ultra-light docker monitor
|
2021-11-21 18:02:31 +00:00
|
|
|
==========================
|
2021-02-13 16:05:42 +00:00
|
|
|
|
|
|
|
This light tool permits:
|
2021-11-21 18:02:31 +00:00
|
|
|
- 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
|
|
|
|
--------------------------
|
|
|
|
```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
|
|
|
|
```
|
|
|
|
|
|
|
|
Configure the stats export
|
|
|
|
--------------------------
|
2021-02-13 19:23:19 +00:00
|
|
|
Open the cron tab in edition mode:
|
2021-11-21 18:02:31 +00:00
|
|
|
```bash
|
|
|
|
crontab -e
|
|
|
|
```
|
2021-02-13 16:05:42 +00:00
|
|
|
|
2021-11-21 18:02:31 +00:00
|
|
|
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
|
|
|
|
```
|
2021-02-13 16:05:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
**Note:**
|
2021-11-21 18:02:31 +00:00
|
|
|
- Normally cron send task outputs (echo) via mail. As the MTA (Mail Transfer Agent),
|
2021-02-13 19:23:19 +00:00
|
|
|
may not be set up, the crontab line redirect the outputs into `/dev/null`.
|
|
|
|
It can also be a path to a log file.
|
2021-02-13 16:05:42 +00:00
|
|
|
- No sudo is needed, crontab is called with current user.
|
|
|
|
|
|
|
|
|
|
|
|
Display stats
|
|
|
|
-------------
|
2021-11-21 18:02:31 +00:00
|
|
|
This step permits to generate an html interactive render from the sqlite stats file.
|
|
|
|
It is simple, just run:
|
|
|
|
```bash
|
2021-12-02 20:01:26 +00:00
|
|
|
./generate_html.sh
|
2021-11-21 18:02:31 +00:00
|
|
|
```
|
|
|
|
|
2021-11-25 21:41:53 +00:00
|
|
|
The report is now accessible in `stats.html`.
|
|
|
|
|
2021-02-13 19:15:17 +00:00
|
|
|
**Note:** if the stats file is in a remote server, one can use `scp` to get it:
|
2021-11-21 18:02:31 +00:00
|
|
|
```bash
|
|
|
|
scp eunuque.caracals.org:/home/caracals/outils/docker-stats-histo/stats.sqlite .
|
|
|
|
```
|
|
|
|
|
|
|
|
Advanced parameters
|
|
|
|
-------------------
|
2021-11-25 21:41:53 +00:00
|
|
|
Both python scripts can have a finer configuration (sqlite and html paths).
|
|
|
|
To see all accepted parameters use `-h` flag, like
|
2021-11-21 18:02:31 +00:00
|
|
|
```bash
|
2021-11-25 21:41:53 +00:00
|
|
|
python save_docker_stats.py -h
|
2021-11-21 18:02:31 +00:00
|
|
|
python generate_html.py -h
|
|
|
|
```
|