I definitely like these Docker and Kubernetes, and thus wanted to share with you how easy it is to set up a home monitoring single pane of glass.

First I selected one of my spare machines, got through a fresh Ubuntu install and got the latest Docker on it. There is an easy website that has a script you can just curl down to your machine https://get.docker.com/ typically curl -o get-docker.sh https://get.docker.com/
. And please review its code before executing, this is at your own risk, but you know what you are doing, right?
My objective was to end-up with something like this below, where you can see indications of your home or room temperature incoming from an InfluxDB, MQTT feed, that is itself fed by a Raspberry Pi Pico and DHT22 temperature and humidity sensors.
The indicators on the picture above are showing a trend over tine, and in a previous article I did show the immediate temperature and humidity but could not show any trend overtime simply because I was missing a timeseries database, but I solved this this time around. Also, in addition of adding the database I decided to use Docker, this added a layer of complexity but I loved the flexibility to being able to turn off and turn on new containers, and changing their set-up easily.
I needed four apps here hence four containers: the mqtt broker “Mosquitto”, “Telegraf”, which is a data broker of some sort, “Influxdb” which is a time series database, and finally “Grafana” to get the nice dashboards. Originally, I wanted to use Prometheus instead of Telegraf+Influxdb but Prometheus works in pull mode only and needs an agent installed on the source machines. It is not possible on my Pi Pico to install anything that big, hence the reason I decided for Telegraf.
I lauched a Mosquitto docker container and reused the micropython code I had from my previous article, and was able to quickly publish a simple json formated message to a topic. The mosquitto container does not require any set-up, just make sure to turn your host firewall down to avoid useless struggles.
After that I did a docker run with Telegraf like so
sudo docker run -d --name telegraf --network mqtt5-network -v $(pwd)/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf
And I made sure I positioned it on the same network as my previous Mosquitto container, so they could reach each other. Same story with InfluxDB, please launch it on the correct network. Immediately after do a docker exec to create the correct database set-up
sudo docker exec -it influxdb influx setup \
--username admin \
--password Welcome1 \
--org my-org \
--bucket mqtt-bucket \
--retention 720h \
--token my-secret-token \
--force
Then Irealised nothing was getting in InfluxDB, so I had to go back to Telegraf and struggled with the configuration file for a while, the command sudo docker logs Telegraf
would show me errors saying it can’t find influxdb and mqtt5 hosts… In the end it was a simple error, I kept launching containers with no networks attached. Useful command here would be sudo docker network ps
Correct telegraf.conf was:
[agent]
interval = "2s"
flush_interval = "6s"
[[inputs.mqtt_consumer]]
servers = ["tcp://mqtt5:1883"] #Use container name or IP from the docker network
topics = ["test/topic"]
client_id = "telegraf_client"
username = "user1"
password = "pikachu"
data_format = "json"
[[outputs.influxdb_v2]]
urls = ["http://influxdb:8086"]
token = "my-secret-token"
organization = "my-org"
bucket = "mqtt-bucket"
precision = "s"
Finally, launched a Grafana container like so:
docker run -d --name=grafana \
--network mqtt5-network \
-p 3000:3000 \
grafana/grafana
And I was ready to roll, opened Firefox and went to my http://localhost:3000, I connected to InfluxDB using the ip address from the docker network, and I had now data incoming and was ready to built my wonderful dashboards.