Do you have any home servers running on your network? Maybe some Raspberry Pis? Wouldn’t it be great to know how they are all performing at any given time? Receive an alert when disk space is running low? Today’s article is going to focus on Glances, a cross-platform monitoring tool for your systems. Our objective is to monitor your systems with Glances and Home Assistant. Once the data is in Home Assistant we can create automations, export the data into a database and add a UI.
Installation
To get started, we need to install Glances on the machines we care about monitoring. In my case, I have one Ubuntu server on my network and a Raspberry Pi that I want to monitor. Glances provides a few different methods to install the software that you can choose from. The installation page can be found here, but I’ll also walk through a couple installation methods. Note: when installing Glances make note of which version you are installing, you’ll need it later when setting up Home Assistant.
First off, you can download a bash script that should do the complete installation. This will install all the dependencies on your machine. I used this method to install on my Raspberry Pis on the network.
1 |
curl -L https://bit.ly/glances | /bin/bash |
Another way is to just install it through PyPI using pip.
1 2 |
pip install glances pip install 'glances[action,browser,cloud,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi]' |
Once one of these finishes you should be able to run glances in web server mode by running:
1 |
glances -w |
Additionally, you can use docker to run Glances in a container. This was the method I used on my Ubuntu server. Notice the GLANCES_OPT="-w"
environment variable used to startup Glances in webserver mode.
1 |
docker run -d --restart="always" -p 61208-61209:61208-61209 -e GLANCES_OPT="-w" -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host docker.io/nicolargo/glances |
No matter the install method you should now be able to access the Glances UI by going to http://IPADDRESS:61208
. If that’s working correctly, Home Assistant should be able to pull in the data.
Start on Boot
If you installed using the bash script or pip you need to set up a service to startup glances automatically when your machine boots up (the docker method already has this build in so you can skip it). To do so, create a file called glances.service
in the /etc/systemd/system
directory with the following:
1 2 3 4 5 6 7 8 9 10 |
[Unit] Description=Glances After=network.target [Service] ExecStart=/usr/local/bin/glances -w Restart=on-abort [Install] WantedBy=multi-user.target |
Then you can enable the service on startup by running sudo systemctl enable glances
. Note the instructions will be different for non-systemd based distributions. To learn more about systemd services check out my article on Starting Docker Compose using systemd on Debian.
If you get stuck at any point please leave me a message in the comments and I’ll try and help out, be sure to read through the Glances docs too.
Home Assistant
Home Assistant has a built-in component for interacting with a Glances installation. Check out the Home Assistant docs for a full listing of all the options. Essentially you have to tell Home Assistant the IP address of the Glances instance and a name for that system. The version
attribute here corresponds to the major version of Glances you installed. If you’re unsure you can run glances --version
on the system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
--- - platform: glances host: 192.168.1.2 name: Server version: 3 resources: - 'disk_use' - 'disk_use_percent' - 'disk_free' - 'cpu_temp' - 'processor_load' - 'memory_use' - platform: glances host: localhost name: HA version: 3 resources: - 'disk_use' - 'disk_use_percent' - 'disk_free' - 'cpu_temp' - 'processor_load' - 'memory_use' |
As seen in my config there is a number of resources you can choose to show up as sensors. Check out the Home Assistant docs for a full list of available resources.
I went ahead and created a group for my sensors as well so they show up in the UI in an organized way. You should be able to see the names of the sensors in the states menu within Home Assistant.
Finally, I wanted to be alerted whenever the disk space is running low on my server. So I created an automation to run nightly to check the remaining disk space. If it’s less than 15 GB on my server or 5 GB on my Raspberry Pi than send me a message on Telegram.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
--- - alias: Check Disk Space on server trigger: - platform: time at: '18:30:00' condition: - condition: numeric_state entity_id: sensor.server_disk_free below: '15' action: - service: notify.zack_telegram data: title: "Server Space" message: "The server has less than 15 GB free" - alias: Check Disk Space on Home Assistant trigger: - platform: time at: '18:30:00' condition: - condition: numeric_state entity_id: sensor.server_disk_free below: '5' action: - service: notify.zack_telegram data: title: "Home Assistant Space" message: "Home Assistant has less than 5 GB free" |
Check out my article on the different notification platforms of Home Assistant if you want to learn more about different notification methods.
Grafana
Now that we’ve got all this data, what else can we do with it? I recommend reading my articles on pushing data to InfluxDB and how to setup Grafana. This gives us more tools to store all our Glances sensor information in a proper database and create visualizations for it. Below is a screenshot from my Grafana dashboard monitoring the RAM usage and CPU load.
Summary
Glacnes is a really cool project that allows you to get more data about the machines running on your home network. It’s really easy to get installed and interfaced with Home Assistant, so if you are new to Home Automation or Home Assistant this is a great starter project.
What other tools are you using to monitor your network and devices? Have any cool automations setup for using Glances data? Let me know in the comments!