How to Use the ‘glances’ Command in Linux
The glances command in Linux provides a comprehensive overview of system performance. Acting as a real-time monitoring system, it offers insights into CPU, memory, disk usage, and more, all in an easy-to-read interface. Similar to commands like top and htop, glances takes system monitoring a step further by displaying additional information and allowing for more customization.
Whether you’re a system admin or web developer, the glances command can be an essential part of your toolkit. It’s particularly handy for those who need to keep an eye on system resources, troubleshoot performance issues, or optimize system efficiency. Alongside tools like vmstat and iostat, glances can provide a more holistic view of your system’s health and performance.
How to Install the glances Command
glances is not typically included by default in most Linux distributions, so you will need to install it. Here’s how you can install and uninstall glances on various Linux systems:
For Ubuntu/Debian-based systems:
To install:
sudo apt-get update sudo apt-get install glances
To uninstall:
sudo apt-get remove glances
For Fedora:
To install:
sudo dnf install glances
To uninstall:
sudo dnf remove glances
For CentOS/RHEL:
To install:
sudo yum install glances
To uninstall:
sudo yum remove glances
For macOS (using Homebrew):
To install:
brew install glances
To uninstall:
brew uninstall glances
How to Use glances
1. Monitor System Resources
Syntax: glances
Explanation: Displays a real-time overview of system resources.
Example: glances
Output:
CPU 5.6% MEM 42.1% SWAP 0.0% LOAD 0.45 0.36 0.31 NETWORK rx 102Kb/s tx 58Kb/s DISK I/O read 0b/s write 20Kb/s
This output shows the current CPU usage at 5.6%, memory usage at 42.1%, no swap usage, network and disk I/O rates, and system load averages.
2. Monitor System Resources with a Specific Refresh Interval
Syntax: glances -t <seconds>
Explanation: Refreshes the display at a specific interval in seconds.
Example: glances -t 5
Output:
CPU 3.2% MEM 40.2% SWAP 0.0% LOAD 0.25 0.30 0.28
This output is similar to the basic command but refreshes every 5 seconds.
3. Monitor Specific Processes by Name
Syntax: glances -p <process_name>
Explanation: Filters the display to show only specific processes by name.
Example: glances -p firefox
Output:
PID 1234 USER john VIRT 2.3G RES 200M CPU 12% MEM 5% TIME+ 2:03 NAME firefox
This output shows details about the Firefox process, including PID, user, virtual and resident memory, CPU and memory usage, and total time.
4. Run Glances in Web Server Mode
Syntax: glances -w
Explanation: Runs glances in web server mode, allowing access via a web browser.
Example: glances -w
Output:
Glances Web User Interface started on http://0.0.0.0:61208/
This output indicates that glances is running as a web server, and the user interface can be accessed through the provided URL.
5. Monitor System Resources with a Specific Configuration File
Syntax: glances -C <path_to_config_file>
Explanation: Starts glances with a specific configuration file.
Example: glances -C /etc/glances/glances.conf
This command allows you to use a custom configuration file to modify the behavior and appearance of glances.
6. Export Statistics to a CSV File
Syntax: glances --export csv --output-file <file.csv>
Explanation: Exports the statistics to a CSV file.
Example: glances --export csv --output-file stats.csv
This command exports the monitored data to a CSV file named stats.csv, allowing for further analysis or record-keeping.
7. Monitor Disk I/O by Disk Name
Syntax: glances -d <disk_name>
Explanation: Monitors specific disk I/O by disk name.
Example: glances -d sda
Output:
DISK I/O sda read 100Kb/s write 50Kb/s
This output shows the read and write speeds specifically for the sda disk.
8. Monitor with Docker Plugin
Syntax: glances --enable-plugin docker
Explanation: Monitors Docker containers using the Docker plugin.
Example: glances --enable-plugin docker
Output:
DOCKER ID 12345678 NAME my_container CPU 5% MEM 10% STATUS Up 3 hours
This output shows details about a specific Docker container, including its ID, name, CPU and memory usage, and status.
9. Display Network Cumulative Stats
Syntax: glances --enable-plugin ip
Explanation: Displays cumulative network stats using the IP plugin.
Example: glances --enable-plugin ip
Output:
NETWORK eth0 rx 1.2GB tx 800MB
This output shows the cumulative received rx and transmitted tx data for the eth0 network interface.
More Linux commands:
| Directory Operations | rmdir · cd · pwd · exa · ls |
| File Operations | cat · cp · dd · less · touch · ln · rename · more · head |
| File System Operations | chown · mkfs · locate |
| Networking | ping · curl · wget · iptables · mtr |
| Search and Text Processing | find · grep · sed · whatis · ripgrep · fd · tldr |
| System Information and Management | env · history · top · who · htop · glances · lsof |
| User and Session Management | screen · su · sudo · open |