Linux provides a wide range of command-line monitoring tools for monitoring various system metrics. We have the top command that monitors various processes, and htop which is an interactive monitoring tool and an improvement of the top command. All these work perfectly fine, but they are limited and don’t provide a complete picture of other equally crucial metrics such as network statistics.
Developed in Python, Glances is a cross-platform tool that provides a user-friendly and elegant overview of the system’s performance.
Key features of the Glances command-line monitoring tool include:
- The ability to monitor 10+ metrics including running processes, CPU and memory utilization, disk usage, and even docker containers.
- Provides REST API as well as XML-RPC for a variety of integrations.
- Various modes: Standalone, client-server mode, and web GUI.
- Ability to render statistics on a web browser.
- Highly customizable.
- Deep and thorough documentation.
How to install Glances in Linux
There are a couple of ways of installing the Glances app. Let us go through each of them before we get down to monitoring various metrics.
Install Glances using package managers in major distributions
First off, Glances is available in official repositories of major Linux distributions such as Ubuntu and CentOS.
Ubuntu
To install Glances on Ubuntu 18.04 and later versions, use the APT package manager as follows:
$ sudo apt install glances
For CentOS 8 and RHEL 8, first, ensure the EPEL package is installed as follows:
CentOS 8
$ sudo dnf install epel-release
RHEL 8
$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Once EPEL is in place, install glances from the AppStream repositories using DNF as follows on CentOS and RHEL:
$ sudo dnf install glances
Install Glances using snap package
Glances tool can also be installed from snap packages as follows. This is ideal if snap is already enabled on your distribution and you are having problems installing from official repositories on your Linux distribution.
$ sudo snap install glances
Snap packages usually hog a lot of disk space. You might want to check that you have adequate disk space.
Install Glances using PIP
And given that Glances is written in Python, you can use pip – which is Python’s package manager to install it. First, ensure that pip is installed on your system. Most systems now use pip3 and once installed, execute the command shown to install glances.
$ sudo pip3 install glances
How use Glances Monitoring Tool to monitor System statistics
The Glances monitoring tool provides 3 main monitoring modes: Standalone, Client-server, and web GUI mode.
Run glances in Standalone mode
Without any command-line arguments, glances provides an overview of the local system’s metrics as shown. This is called the standalone mode. As the name suggests, it provides the performance of the system on which it is installed.
$ glances
At the very top, you can see the private and public IPv4 address of the local system and the uptime at the far right corner. Thereafter, other system metrics are displayed including CPU, memory and swap utilization, load average, disk I/O, network statistics, running processes, and file system I/O.
Run glances in web-GUI mode
A cool feature in glances is the ability to render the metrics on a web browser. Simply invoke the -w flag as shown and you will be provided with a URL that you will use to access the metrics.
$ glances -w
Afterward, launch your browser, and browse the URL provided. Note that the 0.0.0.0 IP can be replaced by the IP address of the server as follows:
http://192.168.2.103:61208
Here, 192.168.2.103 is the IP address of my server.
Better still, you can restrict access to the web page by setting up a password that will require users to authenticate before accessing the dashboard. To achieve this, add the –password option at the end to prompt for password configuration.
$ glances -w --password
Provide a strong password and confirm it. By default, the username is set to glances. Finally, feel free to choose whether or not to save the password. This is entirely up to you to decide.
The next time you visit the URL, an authentication prompt will require you to authenticate before proceeding any further. So type in glances as the username and provide the password you just set up moments ago and click ‘OK’.
Run glances in a client-server mode
Glances also give you an option to monitor remote systems in a server-client setup.
On the remote system to be monitored, run the following command to initialize it in server mode:
$ glances -s
Head over to the client system and execute the command below where IP-address is the IP of the server:
$ glances -c IP-address
Once again, the statistics will be displayed as shown.
How to export a CSV file containing system metrics
Another useful functionality that glances provides is the ability to export the metrics in the form of a CSV file for further analysis. Here, we are exporting the metrics in the export path /home/james/Documents/, and the name of the file is glances.csv.
$ glances --export csv --export-csv-file /home/james/Documents/glances.csv
Alerts in glances
As you might have noted, the metrics are color-coded. These colors hold meaning and here is what each color signifies.
- GREEN: OK (everything is running normally as expected)
- PURPLE: CAUTION (alert)
- BLUE: APPROACHING A CRITICAL STAGE (attention required)
- RED: VERY CRITICAL (critical)
Conclusion
That was an overview of the glances monitoring tool. As you have observed, it’s quite a useful tool that lets you intuitively monitor system statistics with the help of the psutil python library which retrieves system information. It’s cross-platform and can work in virtually any computing environment including Linux, Windows. macOS, and Android.