How to Install Glances System Monitor on Ubuntu 20.04 LTS

Glances System Monitor is free, an open-source command-line tool for process monitoring, system resources such as CPU, Disk I/O, File System, Load Average, Memory, Network Interfaces, and processes. Glances are built with Python language. Glances support cross-platform monitoring, which can be used with a web-based interface.

One of the excellent features Glances supports is setting thresholds in the program. You can set careful, warning, and critical in the configuration file, which will then relay information in colors that can show alerts to systems resources bottlenecks, system resources issues, and much more. Glances, by default, comes with a pre-set list of colors, but you can modify and add additional configs.

The following tutorial will demonstrate how to install or enable and configure Glances System Monitor on Ubuntu 20.04 LTS Focal Fossa Desktop or Server using the command line terminal.

Update Ubuntu

Update your system to ensure all existing packages are updated using the following command.

sudo apt update && sudo apt upgrade -y

Install Glances System Monitor

By default, Ubuntu 20.04 repository features the Glances package, which makes installing the software straightforward. In your terminal, use the following command to begin the installation.

sudo apt install glances -y

Once installed, verify the version, which will check to see if it was installed successfully.

glances --version

Example output:

How to Install Glances System Monitor on Ubuntu 20.04 LTS

Glances should be started and ready to launch from your terminal by default. Verify this by using the following systemctl status command.

systemctl status glances

Example output:

How to Install Glances System Monitor on Ubuntu 20.04 LTS

If the service is not active for some reason, use the following command to enable and start it immediately.

sudo systemctl enable glances --now

How To Use Glances Monitoring System

Once you have installed the program, familiarize yourself with some of the basic commands that the tutorial will now cover.

To open Glances, use the following command.

glances

Example terminal look:

How to Install Glances System Monitor on Ubuntu 20.04 LTS

To exit the Glances, use the following command.

Ctrl+C

Next, you can alternatively open Glances using a timer that may help systems in intensive tasks. By default, the timer is 1, but you can change this as an example:

glances -t 3

This now changes the default time delay from 1 second to 3 seconds. However, you can set this much higher if required.

To bring up the help command, enter the following.

glances -h

Example output:

joshua@ubuntu:~$ glances -h
usage: glances [-h] [-V] [-d] [-C CONF_FILE] [--modules-list]
               [--disable-plugin DISABLE_PLUGIN]
               [--enable-plugin ENABLE_PLUGIN] [--disable-process]
               [--disable-webui] [--light] [-0] [-1] [-2] [-3] [-4] [-5] [-6]
               [--disable-history] [--disable-bold] [--disable-bg]
               [--enable-irq] [--enable-process-extended]
               [--sort-processes {cpu_percent,memory_percent,username,cpu_times,io_counters,name}]
               [--export EXPORT] [--export-csv-file EXPORT_CSV_FILE]
               [--export-csv-overwrite] [--export-json-file EXPORT_JSON_FILE]
               [--export-graph-path EXPORT_GRAPH_PATH] [-c CLIENT] [-s]
               [--browser] [--disable-autodiscover] [-p PORT]
               [-B BIND_ADDRESS] [--username] [--password] [-u USERNAME_USED]
               [--snmp-community SNMP_COMMUNITY] [--snmp-port SNMP_PORT]
               [--snmp-version SNMP_VERSION] [--snmp-user SNMP_USER]
               [--snmp-auth SNMP_AUTH] [--snmp-force] [-t TIME] [-w]
               [--cached-time CACHED_TIME] [--open-web-browser] [-q]
               [-f PROCESS_FILTER] [--process-short-name]
               [--process-long-name] [--stdout STDOUT]
               [--stdout-csv STDOUT_CSV] [--issue] [--api-doc]
               [--hide-kernel-threads] [-b] [--diskio-show-ramfs]
               [--diskio-iops] [--fahrenheit] [--fs-free-space] [--sparkline]
               [--theme-white] [--disable-check-update]
               [--strftime STRFTIME_FORMAT]

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -d, --debug           enable debug mode
  -C CONF_FILE, --config CONF_FILE
                        path to the configuration file
  --modules-list, --module-list
                        display modules (plugins & exports) list and exit
  --disable-plugin DISABLE_PLUGIN, --disable-plugins DISABLE_PLUGIN
                        disable plugin (comma separed list)
  --enable-plugin ENABLE_PLUGIN, --enable-plugins ENABLE_PLUGIN
                        enable plugin (comma separed list)
  --disable-process     disable process module
  --disable-webui       disable the Web Interface
  --light, --enable-light
                        light mode for Curses UI (disable all but top menu)
  -0, --disable-irix    task's cpu usage will be divided by the total number
                        of CPUs
  -1, --percpu          start Glances in per CPU mode
  -2, --disable-left-sidebar
                        disable network, disk I/O, FS and sensors modules
  -3, --disable-quicklook
                        disable quick look module
  -4, --full-quicklook  disable all but quick look and load
  -5, --disable-top     disable top menu (QL, CPU, MEM, SWAP and LOAD)
  -6, --meangpu         start Glances in mean GPU mode
  --disable-history     disable stats history
  --disable-bold        disable bold mode in the terminal
  --disable-bg          disable background colors in the terminal
  --enable-irq          enable IRQ module
  --enable-process-extended
                        enable extended stats on top process
  --sort-processes {cpu_percent,memory_percent,username,cpu_times,io_counters,name}
                        Sort processes by: cpu_percent, memory_percent,
                        username, cpu_times, io_counters, name
  --export EXPORT       enable export module (comma separed list)
  --export-csv-file EXPORT_CSV_FILE
                        file path for CSV exporter
  --export-csv-overwrite
                        overwrite existing CSV file
  --export-json-file EXPORT_JSON_FILE
                        file path for JSON exporter
  --export-graph-path EXPORT_GRAPH_PATH
                        Folder for Graph exporter
  -c CLIENT, --client CLIENT
                        connect to a Glances server by IPv4/IPv6 address or
                        hostname
  -s, --server          run Glances in server mode
  --browser             start the client browser (list of servers)
  --disable-autodiscover
                        disable autodiscover feature
  -p PORT, --port PORT  define the client/server TCP port [default: 61209]
  -B BIND_ADDRESS, --bind BIND_ADDRESS
                        bind server to the given IPv4/IPv6 address or hostname
  --username            define a client/server username
  --password            define a client/server password
  -u USERNAME_USED      use the given client/server username
  --snmp-community SNMP_COMMUNITY
                        SNMP community
  --snmp-port SNMP_PORT
                        SNMP port
  --snmp-version SNMP_VERSION
                        SNMP version (1, 2c or 3)
  --snmp-user SNMP_USER
                        SNMP username (only for SNMPv3)
  --snmp-auth SNMP_AUTH
                        SNMP authentication key (only for SNMPv3)
  --snmp-force          force SNMP mode
  -t TIME, --time TIME  set minumum refresh rate in seconds [default: 2 sec]
  -w, --webserver       run Glances in web server mode (python3-bottle needed,
                        static files not included)
  --cached-time CACHED_TIME
                        set the server cache time [default: 1 sec]
  --open-web-browser    try to open the Web UI in the default Web browser
  -q, --quiet           do not display the curses interface
  -f PROCESS_FILTER, --process-filter PROCESS_FILTER
                        set the process filter pattern (regular expression)
  --process-short-name  force short name for processes name
  --process-long-name   force long name for processes name
  --stdout STDOUT       display stats to stdout, one stat per line (comma
                        separated list of plugins/plugins.attribute)
  --stdout-csv STDOUT_CSV
                        display stats to stdout, csv format (comma separated
                        list of plugins/plugins.attribute)
  --issue               test all plugins and exit (please copy/paste the
                        output if you open an issue)
  --api-doc             display fields descriptions
  --hide-kernel-threads
                        hide kernel threads in process list (not available on
                        Windows)
  -b, --byte            display network rate in byte per second
  --diskio-show-ramfs   show RAM Fs in the DiskIO plugin
  --diskio-iops         show IO per second in the DiskIO plugin
  --fahrenheit          display temperature in Fahrenheit (default is Celsius)
  --fs-free-space       display FS free space instead of used
  --sparkline           display sparklines instead of bar in the curses
                        interface
  --theme-white         optimize display colors for white background
  --disable-check-update
                        disable online Glances version ckeck
  --strftime STRFTIME_FORMAT
                        strftime format string for displaying current date in
                        standalone mode

Examples of use:
  Monitor local machine (standalone mode):
    $ glances

  Display all Glances modules (plugins and exporters) and exit:
    $ glances --module-list

  Monitor local machine with the Web interface and start RESTful server:
    $ glances -w
    Glances web server started on http://0.0.0.0:61208/

  Only start RESTful API (without the WebUI):
    $ glances -w --disable-webui
    Glances API available on http://0.0.0.0:61208/api/

  Monitor local machine and export stats to a CSV file (standalone mode):
    $ glances --export csv --export-csv-file /tmp/glances.csv

  Monitor local machine and export stats to a InfluxDB server with 5s refresh rate (standalone mode):
    $ glances -t 5 --export influxdb

  Start a Glances XML-RPC server (server mode):
    $ glances -s

  Connect Glances to a Glances XML-RPC server (client mode):
    $ glances -c <ip_server>

  Connect Glances to a Glances server and export stats to a StatsD server (client mode):
    $ glances -c <ip_server> --export statsd

  Start the client browser (browser mode):
    $ glances --browser

  Display stats to stdout (one stat per line):
    $ glances --stdout now,cpu.user,mem.used,load

  Display CSV stats to stdout (all stats in one line):
    $ glances --stdout-csv now,cpu.user,mem.used,load

  Disable some plugins (comma separated list):
    $ glances --disable-plugin network,ports

  Enable some plugins (comma separated list):
    $ glances --enable-plugin sensors

Alerts in Glances

As mentioned at the start of the tutorial, Glances has the color for alerts. The following describes what they are.

  1. GREEN: OK (good)
  2. BLUE: CAREFUL (attention)
  3. VIOLET: WARNING (alert)
  4. RED: CRITICAL (critical)

The thresholds that default settings are as follows.

  • careful=50
  • warning=70
  • critical=90

The default configuration can be changed. To do this, open up the file located at /etc/glances/glances.conf. But firstly, let’s make a backup of the original configuration file for safekeeping which you can revert to if you make a mistake and need a fresh copy.

sudo cp /etc/glances/glances.conf /etc/glances/glances-bkup.conf

Next, open up the main configuration file using the nano text editor.

sudo nano /etc/glances/glances.conf

Scroll down, and you will start to see all the settings you can change.

Example:

How to Install Glances System Monitor on Ubuntu 20.04 LTS

For example, you would like to change the memory options.

Change from:

mem_careful=50
mem_warning=70
mem_critical=90

Change to:

mem_careful=75
mem_warning=85
mem_critical=95

As mentioned above, the tutorial has increased the warning signs. However, you can set your own and raise or even lower what you think is appropriate for your environment and use case.

Using the nano text editor, use CTRL+O and CTRL+X to save and exit the file.

Ideally, you should restart the service also using the following command.

sudo systemctl restart glances

Command Options

The following list commands you can use in Glances to configure, find and show what you are looking for.

CommandDescription
aSort processes automatically
cSort processes by CPU%
mSort processes by MEM%
pSort processes by name
iSort processes by I/O rate
dShow/hide disk I/O stats
fShow/hide file system statshddtemp
nShow/hide network stats
sShow/hide sensors stats
yShow/hide hddtemp stats
IShow/hide logs
bBytes or bits for network I/O
wDelete warning logs
xDelete warning and critical logs
1Global CPU or per-CPU stats
hShow/hide this help screen
tView network I/O as a combination
uView cumulative network I/O
qQuit (Esc and Ctrl-C also work)

How to Run Glances In Web Browser

Glances can do this for users who require remote monitoring, as all required dependencies are installed by default.

To initiate the browser function in the program, do the following.

glances -w

Note that you will most likely see in the terminal display “Glances Web User Interface started on http://0.0.0.0:61208” when entering this command. This may look a little confusing, using the server’s IP address.

You can set a password for the web-based monitor by typing the following command.

glances -w --password

To open the web browser for the program, enter your IP server address with the default port 61209 as an example.

http://203.15.33.190:61209

Example:

How to Install Glances System Monitor on Ubuntu 20.04 LTS

For your primary client, you can keep glances running in the background with the following command.

glances -w &

The above creates a background running process. Now you must disown the current state.

disown

If you need to kill the processors in background mode, type the following to kill all active glances sessions.

killall glances

How to Run Client-Server Mode

Another great feature of the Glances program is that it provides client-server architecture. This means you can run glances on multiple remote servers and connect them to your primary client, and all servers must have Glances installed.

Log in to the remote server, and start the glance program in server-side mode.

glances -s

After starting server-side monitoring on all the required servers you need, go to your client system and connect to the system’s IP address running the server-client mode with the following command.

glances -c server-IP-address

Optional – UFW Rules

Ubuntu 20.04 LTS, like previous versions, features the UFW firewall. If this is enabled, it may interfere with remote connections, and you will need to whitelist your IP address locally or externally. Below are some examples only of the most common.

UFW Allow Specific IP Address

For example, to allow for specified IP addresses, use the following command if you are on an internal network and require the systems to communicate together.

sudo ufw allow from 192.168.55.131

UFW Allow Specific IP Address on Specific Port

To enable an IP to connect to your system on a defined port (Glances port “61208”), type the following.

sudo ufw allow from 192.168.55.131 to any port 61208

Allow Subnet Connections to a Specified Port

If you require a whole range of connections from an IP range subnet to a particular port, you can enable this by creating the following rule.

sudo ufw allow from 192.168.1.0/24 to any port 61208

This will allow all IP addresses from 192.168.1.1 to 192.168.1.254 to connect to port 61208.

Comments and Conclusion

In the tutorial, you have learned how to install the Glances System Monitor on Ubuntu 20.04 LTS, a step above the default “top” package for monitoring system resources and processors that ship with default Ubuntu installations. This package is ideal, especially if you want a better system overview, and it covers much more information and presents it in color codes to signal what the data in front of you means and how it affects your server.

The extra benefit of remote monitoring makes this one of the more popular options for simple server monitoring. It continues to get better with an active development continuing to this day.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!