Install & Use Glances to monitor Ubuntu Server.
Whether you're a system administrator or a casual desktop user, you've probably heard of the most popular terminal-based system monitoring tools, TOP, and its colorful, feature-rich cousin-in-law HTOP. 😬😅
Glances is a command-line system monitor. In addition to the traditional top and htop commands, the program provides process information as well as additional real-time statistics on the file system, network, hardware components, and so on. It has a ncurses interface and also has a web interface that can be accessed from any device.
Installation
On Debian/Ubuntu-based distributions, you can use the following command:
$ sudo apt install glances
You can also install the latest glances using snap package:
$ sudo snap install glances
Since glances is based on Python, you can also use PIP
to install it on most Linux distributions. Install PIP first and then use it to install Glances:
$ sudo pip3 install glances
Last but not least; you can use the auto-install script provided by glances developer. Though we at Snubmonkey don’t recommend running random scripts directly on your system. It is entirely up to you.
$ curl -L https://bit.ly/glances | /bin/bash
or
$ wget -O- https://bit.ly/glances | /bin/bash
Other ways to install glances can be found in their documentation, and it can also be installed as a Docker container.
Using Glances - Standalone
Simply run the following command to view the details of your own system:
$ glances
It should show information about your system, as shown in the image below.
Searching/Filtering Processes
Simply press the Enter key to locate a specific process. As shown below, a search box will appear:
You can search for a process name or a regular expression here. Other parameters, such as the username or command line arguments, can also be used to narrow down your search. For example, to find processes belonging to the root user, enter username:root.
To leave the filtered process list, press the capital E key. It should go back to the glances page.
Server/Client Mode
If you want to access data from another system through a terminal without using ssh __ use: server and client mode.
Run glances
in server mode
$ glances -s
...
..
.
Glances XML-RPC server is running on 0.0.0.0:61209
You can now connect to the server machine on the client by using:
$ glances -c SERVER_IP
Replace SERVER_IP
with the IP address or the hostname of the server.
If you don't want to log in to the server, this is a great alternative. However, in order to obtain performance data from the remote system, both the remote/client computer must have glances installed.
Note: Open port 61209 using the command
sudo ufw allow 61209/tcp
sudo ufw reload
Web server Mode
Furthermore, glances
has a "webserver mode" that does not require you to install anything on your local system.
First, launch glances
in this mode on the remote system as follows:
$ glances -w
The preceding command will occupy the terminal, and closing it will also stop the webserver. As a result, you can use &
– to run it in the background for the current session.
$ glances -w &
Output
Glances Web User Interface started on http://0.0.0.0:61208/
Open your web browser and type-
http://SERVER-IP:61208
Replace SERVER-IP with the IP address of the machine in which you have installed glances.
To change the refresh rate of the page to a faster or slower value than the default rate, just append the date at the end of the URL. Ie, if you want the values to refresh after every 4 seconds, then the URL will be http://server-ip:61208/4
.
Protect your Web server with a login/password
You may want to password-protect the web mode so that only authorized users can access it; glances is the default username.
$ glances -w --password
Define the Glances webserver password (glances username):
Password (confirm):
Do you want to save the password? [Yes/No]: y
Glances Web User Interface started on http://0.0.0.0:61208/
You can find more information on configuring password and username in the quickstart guide.
Create Glances Service file
Normally, you must start the glances web server every time you want to access it via the network using a browser. However, to run automatically with system boot and in the background, use the following commands to create a service.
$ sudo nano /usr/lib/systemd/system/glances.service
Now, paste and save the below-given block of text:
[Unit]
Description = Glances in Web Server Mode
After = network.target
[Service]
ExecStart = /usr/bin/glances -w -t 4
[Install]
WantedBy = multi-user.target
#1 Restart your system.
#2 Enable and start the service file:
$ sudo systemctl enable glances.service
$ sudo systemctl start glances.service
$ sudo systemctl status glances.service
Output
Configuring Glances
Glances
' behavior can be customized using the glances.conf
configuration file. A template is available in the /usr{,/local}/share/doc/glances
(Unix-like) directory. You can put your own glances.conf
file in the following locations:~/.config/glances/
- /etc/glances/
- /usr/share/docs/glances/
. If neither of these directories exists on your system, you must manually create them. If you want the warnings to be triggered at custom values rather than the default values, each section must be explicitly stated in that glances.conf
file. For example, if you want to specify some custom alert values for CPU usage, you can do so in the [cpu] section as shown below.
[cpu]
disable=False
user_careful=50
user_warning=70
user_critical=90
iowait_careful=50
iowait_warning=70
iowait_critical=90
system_careful=50
system_warning=70
system_critical=90
steal_careful=50
steal_warning=70
steal_critical=90
I hope this gave you a good deal of information on Glances.