Glances is a robust, open-source, and platform-independent system monitoring tool elegantly built in Python. This real-time tool provides comprehensive insights into system resources such as CPU, memory, load, disk I/O, processes, file system space, and network interfaces. Designed with both command-line and web-based interfaces, Glances leverages the psutil library to retrieve system data, offering configurable visual thresholds (‘careful,’ ‘warning,’ ‘critical’) highlighted in varied colors for easy monitoring.
Features
With Glances, you can efficiently monitor the following metrics:
- Usage of RAM, swap, and free memory.
- Average system CPU load.
- Number of active and idle processes.
- Disk I/O activities.
- File system space monitoring.
- Real-time date and time display.
This guide will walk you through the process of installing and utilizing Glances to monitor system resources on an Ubuntu 22.04 server.
Prerequisites
- A server running Ubuntu 22.04.
- Administrator or root privileges configured on the server.
Install Glances
Glances is readily available within the default Ubuntu repositories. To install, execute the following command:
apt-get install glances -y
Post-installation, verify the Glances version using:
glances --version
Expected output:
Glances v3.2.4.2 with PsUtil v5.9.0 Log file: /root/.local/share/glances/glances.log
Check Glances’ status with:
systemctl status glances
Expected output:
? glances.service - Glances Loaded: loaded (/lib/systemd/system/glances.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2022-08-21 11:46:53 UTC; 10min ago Docs: man:glances(1) https://github.com/nicolargo/glances Main PID: 23387 (glances) Tasks: 1 (limit: 2242) Memory: 34.5M CPU: 757ms CGroup: /system.slice/glances.service ??23387 /usr/bin/python3 /usr/bin/glances -s -B 127.0.0.1 Aug 21 11:46:53 ubuntu2204 systemd[1]: Started Glances.
Launch Glances Command Interface
To monitor system resources via command line, launch Glances with:
glances
You should see the following screen:
The color codes used are:
- Green: Normal operation.
- Blue: Caution.
- Violet: Warning.
- Red: Critical issue.
Default thresholds:
- careful=50
- warning=70
- critical=90
To update these settings, edit /etc/glances/glances.conf
:
nano /etc/glances/glances.conf
Modify as needed:
[quicklook] # Define CPU, MEM and SWAP thresholds in % cpu_careful=50 cpu_warning=70 cpu_critical=90 mem_careful=50 mem_warning=70 mem_critical=90 swap_careful=50 swap_warning=70 swap_critical=90
Save and exit the file when done.
Keyboard Shortcuts of Glances
Glances offers useful keyboard shortcuts for better navigation:
- m: Sort by memory usage
- p: Sort by process name
- c: Sort by CPU usage
- i: Sort by I/O rate
- s: Toggle sensor stats
- n: Toggle network stats
- x: Clear warning/critical logs
- d: Toggle disk I/O stats
- a: Auto-sort processes
- f: Toggle file system stats
- y: Toggle HDD temperature stats
- l: Toggle logs
- h: Toggle help screen
- q: Quit
- w: Clear warning logs
Exit Glances using Ctrl+C. For a full options list, run:
glances -h
Run Glances in Web Server Mode
To monitor system resources via a web browser, create a systemd service file for Glances’ web mode:
nano /usr/lib/systemd/system/glancesweb.service
Add:
[Unit] Description = Glances in Web Server Mode After = network.target [Service] ExecStart = /usr/bin/glances -w -t 5 [Install] WantedBy = multi-user.target
Save and close, then reload systemd:
systemctl daemon-reload
Start and enable the Glances web service:
systemctl start glancesweb systemctl enable glancesweb
Check its status:
systemctl status glancesweb
Expected output:
? glancesweb.service - Glances in Web Server Mode Loaded: loaded (/lib/systemd/system/glancesweb.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2022-08-21 11:52:00 UTC; 6s ago Main PID: 24107 (glances) Tasks: 1 (limit: 2242) Memory: 26.0M CPU: 488ms CGroup: /system.slice/glancesweb.service ??24107 /usr/bin/python3 /usr/bin/glances -w -t 5 Aug 21 11:52:00 ubuntu2204 systemd[1]: Started Glances in Web Server Mode.
Glances listens on port 61208. Verify it with:
ss -antpl | grep glances
Expected output:
LISTEN 0 5 0.0.0.0:61208 0.0.0.0:* users:(("glances",pid=24107,fd=7)) LISTEN 0 5 127.0.0.1:61209 0.0.0.0:* users:(("glances",pid=23387,fd=4))
In your browser, access http://your-server-ip:61208 to view:
Utilize the same keyboard shortcuts for filtering outputs.
Conclusion
Congratulations! You have successfully installed and configured Glances on your Ubuntu 22.04 server. Glances can now provide both command-line and browser-based monitoring of system resource usage. Should you have any questions, feel free to reach out.
Frequently Asked Questions
- How do I update Glances?
You can update Glances using the package manager with the command:apt-get update && apt-get upgrade glances
. - Can I customize the display interface?
Yes, you can modify the configuration file at/etc/glances/glances.conf
to suit your preferences. - What ports need to be open for web access?
Ensure port 61208 is open in your firewall for external access. - How do I stop Glances from running?
Usesystemctl stop glances
orsystemctl stop glancesweb
to stop the service.