A network monitor for my home network. Based on docker-compose and Ansible. It uses ideas and code from frdmn/docker-speedtest-grafana.
The goal is to have a monitoring of the internet access as I would want it on my small home server. All this packaged in a Docker Compose. And easy to deploy on a fresh Unix server thru an Ansible script.
In a first version, these are the components I have integrated:
At a later stage I could add monitoring of my FritzBox, logging the ping time to google and may be more.
As a first step, make sure the file hosts
points to the machine you want to provision (i.e. your home server or a local VM if you are testing). To get a starting point you can cp hosts.sample hosts
and then edit the hosts
file.
In order to deploy the services, these are the commands that need to be executed:
# Install the required roles (only needed to run once or if requirements changed)
ansible-galaxy install -r requirements.yml
ansible-galaxy collection install -r requirements-collections.yml
ansible-playbook setup.yml
Once the infrastructure (i.e. the docker daemon) is installed on the server and you only want to push modifications:
ansible-playbook setup.yml --tags deploy
In order to see what's happening on the server:
ssh <Server IP or name>
# To follow the changes 'real time' I usually have one terminal like so:
watch docker ps
Once the services are running, Grafana can be accessed in the browser at http://<IP Address of the server>:80
.
Configurations can be made in the vars/all.yml
file and are pretty self explanatory.
- Build images (26.6.2021): The
docker-compose
file now has abuild
section, and builds the speedtest docker image when launched. This way we can add / modify functionality in theindex.js
node script and see it reflected rigth after start. - Properly see network drop outs (29.6.2021): When my network stops working, I now return 0-values, so I can recognize drop-outs in the graph like so:
- Use variables for paths (30.6.2021), so it can also be executed on my local Mac w/o polluting it.
- Add round trip to Google: Another way than speedtest to measure latency is pinging google. And as it is far less heavy than using speedtest, I could add this measurement.
- Monitor the server itself: In order to have a real monitoring of my home infrastructure, I should add some metrics of my server on which the docker-compose setup is running: Processor, disk space, memory usage...
- Monitor Fritz!Box, especially the data volume bein up- and downloaded.
- Show logs of all dockers in an easy way, i.e. something similar to
docker logs all
.
In order to test my Ansible scripts, I use locally running VM using multipass from Ubuntu: It worked best for me in order to easily get fresh instances up and running in order to test my Ansible scripts.
See here for my Multipass Cheatsheet and for a guide for testing the Ansible scripts with multipass.
Related and unrelated...
- Repeating problems with multipass were solved in this thread, or at least reliably analyzed and worked-around: Hello, I believe I have the same or at least similar problem. It occurs after I reboot my host (macOS Mojave 10.14.6). If the VMs were stopped before rebooting, I can restart them just fine. But if any VMs were running when the host reboot, they end up "stuck". Workarounds: 1- Avoid "stuck" state: Before rebooting, stop the VM. After rebooting, start the VM. 2- Recover from "stuck" state: run command to stop the vm, then reboot again, and then start the VM.
- An interesting thought: Do I need
docker-compose
or can I use plain Ansible? See this article. - A Promise-based JavaScript FRITZ!Box API. - although I am not sure it picks up the data I am most interested in: The actual up- and download volume.
- FRITZBOX MONITORING MIT GRAFANA DASHBOARD, May 2021: A good article, but also uses the GO Fritz-Box Exporter. But references a nice Grafana Dashboard for FritzBox-Data.
- How to create a sudo user on Ubuntu and allow SSH login
- Using VirtualBox in Multipass on macOS
- Building, saving, and loading container images with Ansible - redhat, July 2020 explains nicely how to build on a remote host and how to export & import images.
- Increase VirtualBox Disk Size (after having resized the Virtual Disk with VirtualBox)
- A good showcase using Ansible and Docker Compose: Ansible-Tutorial: Setup von Docker, MySQL und WordPress mit Ansible [aktualisiert 2020]
- A fully functioning Speedtest / InfluxDB / Grafana setup
- geerlingguy's role
- A tutorial video by Nana. And check the Gitlab Repo that goes with the tutorial and contains all the samples.