Monitor Your Systems with Glances and Home Assistant

This post may contain affiliate links. Please read my disclaimer for more info.

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.

Another way is to just install it through PyPI using pip.

Once one of these finishes you should be able to run glances in web server mode by running:

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.

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:

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.

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.

Server UI in 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.

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.

Grafana with Glances Screenshot

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!