Home Assistant - Monitor Performance of Docker Containers
Within my Home Assistant dashboard I wanted to see information about my Docker containers. For example CPU use, memory use and status (running/not running). After some research I came across this fork of the ‘Docker Monitor’ integration.
Monitoring Docker can also be done with Telegraf. The advantage of using Telegraf is that you can for example configure your own bucket within InfluxDB with a short retention and that many metrics are available. You can then use the data in Home Assistant with the help of the InfluxDB sensor
Mount the Docker Daemon
First make sure the Docker daemon is mounted within the Home Assistant Docker container.
In summary, you need to add the following to your Docker run script. For me this is homeassistant_run.sh
:
-v /var/run/docker.sock:/var/run/docker.sock \
Install the Docker Monitor Integration
The installation of the integration can be done via HACS or possibly via a git clone
command. But I made the choice to install the integration with a simple copy job.
Go to the config
directory of your Home Assistant Docker container:
cd config
Then make sure the custom_components/docker_monitor
directory exists:
mkdir -p custom_components/docker_monitor
Go to the Docker Monitor directory and download the files (raw
format!):
# Go to the docker monitor directory
cd custom_components/docker_monitor
# Download the files
wget https://raw.githubusercontent.com/guillaumelamirand/docker-monitor/master/custom_components/docker_monitor/__init__.py && wget https://raw.githubusercontent.com/guillaumelamirand/docker-monitor/master/custom_components/docker_monitor/const.py && wget https://raw.githubusercontent.com/guillaumelamirand/docker-monitor/master/custom_components/docker_monitor/manifest.json && wget https://raw.githubusercontent.com/guillaumelamirand/docker-monitor/master/custom_components/docker_monitor/sensor.py
Exit Nano (CTRL-X) and save the changes.
Configuration
Now go back to the config
directory of your Home Assistant Docker container and edit configuration.yaml
:
sudo nano configuration.yaml
Add the docker_monitor
configuration:
# Example configuration.yaml entry
docker_monitor:
containers:
- homeassistant
- mariadb
- influxdb
monitored_conditions:
- docker_version
- container_status
- container_memory_usage
- container_memory_percentage_usage
- container_cpu_percentage_usage
Adjust the following:
containers:
Add your own Docker container names
monitored_conditions:
Add your own monitored conditions
Exit Nano (CTRL-X) and save the changes.
Groups (optional)
Personally, I found it useful to group the sensors by the name of the app.
Add the following to the configuration.yaml
:
group: !include groups.yaml
Create a groups.yaml
in the config
directory:
sudo nano groups.yaml
Now add the groups, for example for the homeassistant
, mariadb
and influxdb
containers:
app_homeassistant:
name: Home Assistant
entities:
- binary_sensor.updater
- sensor.docker_monitor_homeassistant_cpu_use
- sensor.docker_monitor_homeassistant_memory_use
- sensor.docker_monitor_homeassistant_memory_use_percent
- sensor.docker_monitor_homeassistant_status
app_mariadb:
name: MariaDB
entities:
- sensor.docker_monitor_mariadb_cpu_use
- sensor.docker_monitor_mariadb_memory_use
- sensor.docker_monitor_mariadb_memory_use_percent
- sensor.docker_monitor_mariadb_status
app_influxdb:
name: InfluxDB
entities:
- sensor.docker_monitor_influxdb_cpu_use
- sensor.docker_monitor_influxdb_memory_use
- sensor.docker_monitor_influxdb_memory_use_percent
- sensor.docker_monitor_influxdb_status
I also added the
binary_sensor.updater
to the Home Assistant group.
Exit Nano (CTRL-X) and save the changes.
Using Docker Monitor
Now go to the Home Assistant UI and check your configuration via Configuration
> Settings
> Server Controls
> Check Configuration
(the button).
When the configuration is valid restart the server. After restarting you should find your sensors (and groups if configured) in the Overview
when this dashboard is still maintained by Home Assistant (which is default):
Read other notes
Tags
Notes mentioning this note
- Docker - Home Assistant Container Setup with MariaDB and InfluxDB 2.x
Here I describe my setup of the Home Assistant container with MariaDB and InfluxDB 2.x.
- Docker - Telegraf Container Setup with InfluxDB to Monitor Docker
Here I describe my setup of the Docker Telegraf container. Telegraf from InfluxData is a server agent for collecting metrics...
Comments
No comments found for this note.
Join the discussion for this note on this ticket. Comments appear on this page instantly.